File manager - Edit - /home/autoph/public_html/projects/Rating-AutoHub/public/css/customer_update.zip
Back
PK 8F�Z8��! �! activity_modal.jsnu �[��� (function ($, undefined) { $.fn.getCursorPosition = function () { var el = $(this).get(0); var pos = 0; if ('selectionStart' in el) { pos = el.selectionStart; } else if ('selection' in document) { el.focus(); var Sel = document.selection.createRange(); var SelLength = document.selection.createRange().text.length; Sel.moveStart('character', -el.value.length); pos = Sel.text.length - SelLength; } return pos; } })(jQuery); const $customerActFrm = $('.customer-activity-form'); const $customerInsuranceActFrm = $('.customer-activity-close-deal-form'); function templateEvt() { $customerActFrm.find('.customer-activity-template').each(function () { $(this).on('click', function (e) { var position = $customerActFrm.find("[name=activity]").getCursorPosition() var content = $customerActFrm.find("[name=activity]").val(); var newContent = content.substr(0, position) + $(this).text()+ content.substr(position); $customerActFrm.find("[name=activity]").val(newContent); $customerActFrm.find("[name=activity]").trigger("focus"); }); }); } function closeDealEvt() { $customerActFrm.find('.btn-close-deal').on("click", function (e) { $('#modal-customer-activity').modal('hide'); $('#modal-customer-activity-close-deal').modal('show'); $('#modal-customer-activity-close-deal').off('hidden.bs.modal').on('hidden.bs.modal', function () { $('#modal-customer-activity').modal('show'); }); return false; Swal.fire({ icon: 'question', html: 'Are you sure you want to close the deal?', showDenyButton: false, showCancelButton: true, confirmButtonText: `Confirm`, denyButtonText: `Don't Confirm`, showClass: { backdrop: "swal2-noanimation", // disable backdrop animation popup: "", // disable popup animation icon: "", // disable icon animation }, hideClass: { popup: "", // disable popup fade-out animation }, }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "/customer", method: "POST", dataType: 'json', data: { apiKey: '3695340036334748', customer_id: customer_record_id }, beforeSend: function () { sweetAlertSimple('info', 'Oops...', 'Removing customer...') }, success: function (result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); var url = location_url + "customer.php"; window.location.href = url; } else { sweetAlertSimple('error', 'Oops...', result.message) } }, error: function () { sweetAlertSimple('error', 'Oops...', 'Error has been occurred, please try again.mmmm') } }); } else if (result.isDenied) { // Swal.fire('', 'Changes are not saved', 'info') } }); }); } function activityFrmEvt() { $customerActFrm.on("submit",function (event) { var formData = new FormData(this); formData.append( "csrf_token", $("meta[name='csrf-token']").attr("content") ); formData.append("id", (typeof activity_id === 'undefined') ? "" : activity_id); formData.append("customer_id", (typeof customer_record_id === 'undefined') ? "" : customer_record_id); formData.append("vehicle_id", (typeof vehicle_record_id === 'undefined') ? "" : vehicle_record_id); $.ajax({ url: "/customer/activity/store", // url: url.store, type: "POST", data: formData, // timeout: 9000, processData: false, contentType: false, beforeSend: function () { $customerActFrm.find("button[type=submit]").prop("disabled", true); }, success: function (result) { $customerActFrm.find("button[type=submit]").prop("disabled", false); if (parseInt(result.status) === 1) { sweetAlertSimple('success', '', result.message); $customerActFrm.trigger("reset"); $('#modal-customer-activity').modal('hide'); } else { sweetAlertSimple('error', '', result.message) } }, error: function () { sweetAlertSimple('error', '', 'Error has occured.') $customerActFrm.find("button[type=submit]").prop("disabled", false); }, }); event.preventDefault(); }); } function activityInsuranceFrmEvt() { $customerInsuranceActFrm.on("submit",function (event) { var formData = new FormData(this); formData.append( "csrf_token", $("meta[name='csrf-token']").attr("content") ); formData.append("id", (typeof activity_insurance_id === 'undefined') ? "" : activity_insurance_id); formData.append("customer_id", (typeof customer_record_id === 'undefined') ? "" : customer_record_id); formData.append("vehicle_id", (typeof vehicle_record_id === 'undefined') ? "" : vehicle_record_id); $.ajax({ url: "/customer/activity/insurance/store", // url: url.store, type: "POST", data: formData, // timeout: 9000, processData: false, contentType: false, beforeSend: function () { $customerInsuranceActFrm.find("button[type=submit]").prop("disabled", true); }, success: function (result) { $customerInsuranceActFrm.find("button[type=submit]").prop("disabled", false); if (parseInt(result.status) === 1) { // alert("1") $customerInsuranceActFrm.trigger("reset"); $customerActFrm.trigger("reset"); $('#modal-customer-activity-close-deal').off('hidden.bs.modal'); $('#modal-customer-activity-close-deal').modal('hide'); sweetAlertSimple('success', '', result.message); } else { sweetAlertSimple('error', '', result.message) } }, error: function () { sweetAlertSimple('error', '', 'Error has occured.') $customerInsuranceActFrm.find("button[type=submit]").prop("disabled", false); }, }); event.preventDefault(); }); } function initDateFields() { $(".activity-date").datetimepicker({ format: "L", }); } function refreshTableActivities() { var $table = $('#activity-table') $table.bootstrapTable('destroy').bootstrapTable(); $(function() { $table.bootstrapTable('refresh', { url: 'app/table/customer_activity.php' }); }) } function queryParamsActivities(params) { return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, customer_id: ((typeof customer_record_id === 'undefined') ? "" : customer_record_id), vehicle_id: ((typeof vehicle_record_id === 'undefined') ? "" : vehicle_record_id), }; } $(function () { $('#datetimepicker2').datetimepicker({ format: 'DD/MM/YYYY' }); // alert(vehicle_record_id) if (typeof vehicle_record_id !== 'undefined') { if (vehicle_record_id) { // hide vehicle information $customerInsuranceActFrm.find(".activity-vehicle-info").hide(); // $customerInsuranceActFrm.find("[name=conduction_sticker]").hide(); } } initDateFields(); activityFrmEvt(); activityInsuranceFrmEvt(); templateEvt(); closeDealEvt(); });PK 8F�Z {�� � customer_form.jsnu �[��� var force_update = 0; var force_update_reason = ""; function removeextra() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9a-zA-Z]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function removeextranumonly() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9()-]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function getCustomerAllModalData() { var /* Create an object. */ obj = {}, /* Create a variable that references the current object (default → obj). */ ref = obj; /* Iterate over every input. */ $("#modal-customer :input").each(function () { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute("nodetype") == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute("json-modal") == "true") { ref[id] = $(this).val(); } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function sweetAlertSimple(icon, title, text) { // Swal.fire({ // icon: icon, // title: title, // text: text, // allowEnterKey: true // default value // }) toastr.remove(); switch (icon) { case "success": toastr.success(text); break; case "info": toastr.info(text); break; case "warning": toastr.warning(text); break; case "error": toastr.error(text); break; } } function getAllDataSourceTableData() { var $table = $("#data-source-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { var new_header = $(this).html().replace(/\s/g, "_").replace(/\./g, ""); header.push(new_header); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { if (header[i] == "Customer_No") { var key = header[i], value = $(this).find("input").val(); row[key] = value; } else { var key = header[i], value = $(this).find("select").val(); row[key] = value; } }); rows.push(row); }); console.log(rows); return rows; } function checkIfDataSourceIncomplete() { rows = getAllDataSourceTableData(); var dataSourceJsonRow = rows; var hasMatch = true; for (var index = 0; index < dataSourceJsonRow.length; ++index) { var dataSourceJson = dataSourceJsonRow[index]; if ( // dataSourceJson.Customer_No == "" || dataSourceJson.DMS == "" || dataSourceJson.Company == "" || dataSourceJson.Dealer == "" ) { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function handleError(xhr, status, error) { //hide loader sweetAlertSimple("error", "Oops...", "Error has occurred, Try again..."); $("#proceed-button").attr("disabled", false); $(".customer-modal-overlay").hide(); force_update = 0; force_update_reason = ""; } function refreshModalCities() { $.ajax({ url: "api/city/city.php", type: "GET", dataType: "json", data: { apiKey: "5881641680981247", }, beforeSend: function () { $("#mod-dd-city-1").prop("disabled", true); $("#mod-dd-city-2").prop("disabled", true); }, success: function (result) { $("#mod-dd-city-1").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-2").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-1").prop("disabled", false); $("#mod-dd-city-2").prop("disabled", false); }, }); } function checkIfChildrenIncomplete() { rows = getAllChildrenTableData(); var childrenJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; for (var index = 0; index < childrenJsonRow.length; ++index) { var childrenJson = childrenJsonRow[index]; if ( childrenJson.Firstname == "" || childrenJson.Lastname == "" || childrenJson.Birthday == "" ) { hasMatch[0] = false; break; } if (!isEmpty(childrenJson.Mobile)) { if (childrenJson.Mobile.length < 10) { hasMatch[1] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllChildrenTableData() { var $table = $("#children-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function isEmail(email) { var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return regex.test(email); } function isEmpty(string) { var flag = false; try { if (string.trim() == "") { flag = true; } else if (string == null) { flag = true; } else if (typeof string === "undefined") { flag = true; } } catch (err) { // console.log(err); flag = true; } return flag; } function checkIfContactPersonIncomplete() { rows = getAllContactPersonTableData(); var contactPersonJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; hasMatch[2] = true; for (var index = 0; index < contactPersonJsonRow.length; ++index) { var contactPersonJson = contactPersonJsonRow[index]; if ( contactPersonJson.Fullname == "" /* || contactPersonJson.Lastname == "" || contactPersonJson.Mobile == ""*/ ) { hasMatch[0] = false; break; } if (contactPersonJson.Email != "") { if (!isEmail(contactPersonJson.Email)) { hasMatch[1] = false; break; } } if (!isEmpty(contactPersonJson.Mobile)) { if (contactPersonJson.Mobile.length < 10) { hasMatch[2] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllContactPersonTableData() { var $table = $("#contact-person-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function addCustomerChildren() { var children_list = document.getElementById("children-list"); const children_list_base = document.querySelector( "#children-list-clone tbody tr" ); children_list.appendChild(children_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var ChildrenIdDateNow = uniqId(); var newChildrenFirstnameId = "children-firstname-" + ChildrenIdDateNow; var newChildrenLastnameId = "children-lastname-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "div-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "append-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayId = "children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "children-birthday-div-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "children-birthday-append-" + ChildrenIdDateNow; var newChildrenMobileId = "children-mobile-append-" + ChildrenIdDateNow; var item = []; item[0] = newChildrenFirstnameId; item[1] = newChildrenLastnameId; item[2] = newChildrenBirthdayId; item[3] = newChildrenMobileId; $("#mod-children-firstname").attr("id", newChildrenFirstnameId); $("#mod-children-lastname").attr("id", newChildrenLastnameId); $("#mod-children-mobile").attr("id", newChildrenMobileId); $("#mod-children-birthdate") .attr("id", newChildrenBirthdayId) .data("target", "#" + newChildrenBirthdayDivId) .inputmask(); $("#mod-children-birthdate-append") .attr("id", newChildrenBirthdayAppendId) .data("target", "#" + newChildrenBirthdayDivId); $("#mod-children-birthdate-div") .attr("id", newChildrenBirthdayDivId) .datetimepicker({ format: "L", }); return item; } function addCustomerContactPerson() { var contact_person_list = document.getElementById("contact-person-list"); const contact_person_list_base = document.querySelector( "#contact-person-list-clone tbody tr" ); contact_person_list.appendChild(contact_person_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var contactPersonIdDateNow = uniqId(); var newContactPersonFullnameId = "contact-person-fullname-" + contactPersonIdDateNow; var newContactPersonFirstnameId = "contact-person-firstname-" + contactPersonIdDateNow; var newContactPersonLastnameId = "contact-person-lastname-" + contactPersonIdDateNow; var newContactPersonEmailId = "contact-person-email-" + contactPersonIdDateNow; var newContactPersonMobileId = "contact-person-mobile-" + contactPersonIdDateNow; var item = []; item[0] = newContactPersonFullnameId; item[1] = newContactPersonEmailId; item[2] = newContactPersonMobileId; $("#modal-contact-person-fullname").attr("id", newContactPersonFullnameId); $("#modal-contact-person-email").attr("id", newContactPersonEmailId); $("#modal-contact-person-mobile").attr("id", newContactPersonMobileId); return item; } function addRowInterest() { $("#addRow").click(function () { if ( !checkIfInterestIncomplete() && $("#interest-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the interest/hobbies details first" ); } else { addInterestItem(); } }); $("#interest-list").on("click", ".btnRemove", function () { $(this).closest("tr").remove(); }); } function getAllInterestTableData() { var $table = $("#interest-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfInterestIncomplete() { rows = getAllInterestTableData(); var interestJsonRow = rows; var hasMatch = true; for (var index = 0; index < interestJsonRow.length; ++index) { var interestJson = interestJsonRow[index]; if (interestJson.Category == "" || interestJson.Interest == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function addRowAffiliations() { $("#addRowAffiliations").click(function () { if ( !checkIfAffiliationsIncomplete() && $("#affiliations-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the affiliation details first" ); } else { addAffiliationsItem(); } }); $("#affiliations-list").on("click", ".btnRemoveAffiliations", function () { $(this).closest("tr").remove(); }); } function getAllAffiliationsTableData() { var $table = $("#affiliations-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html().replace(/\s/g, "_").replace(/\./g, "")); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfAffiliationsIncomplete() { rows = getAllAffiliationsTableData(); var jsonRow = rows; var hasMatch = true; for (var index = 0; index < jsonRow.length; ++index) { var json = jsonRow[index]; if (json.Category == "" || json.Affiliations == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function refreshModalReligion() { $.ajax({ url: "api/religion/religion.php", method: "POST", data: { apiKey: "2011315786548487", }, cache: false, beforeSend: function () {}, success: function (result) { var obj = jQuery.parseJSON(result); $("#mod-dd-religion").select2({ tags: true, placeholder: "Select Religion", allowClear: true, data: obj, }); }, }); } function resetCustomerModal() { $("#mod-dd-nationality").val("608").trigger("change"); $("#interest-list-table > tbody").empty(); $("#affiliations-list-table > tbody").empty(); $("#contact-person-list-table > tbody").empty(); $("#children-list-table > tbody").empty(); $("#data-source-list-table > tbody").empty(); $("#educational-bg-list-table > tbody").empty(); $("#car-clubs-list-table > tbody").empty(); $("#unit-association-list-table > tbody").empty(); $("#political-clubs-list-table > tbody").empty(); $("#network-marketing-list-table > tbody").empty(); $("#media-publications-list-table > tbody").empty(); $("#sme-groups-list-table > tbody").empty(); $("#fraternities-sororities-list-table > tbody").empty(); $("#facebook-groups-list-table > tbody").empty(); $("#celebrity-influencers-list-table > tbody").empty(); addCustomerModalTabSelectedTab(1); } function checkFieldsModal(isIndividual) { if (isIndividual) { $(".children-stepper").show(); $(".interest-stepper").show(); $(".interest-list").show(); $("#div-mod-firstname").show(); $("#div-mod-middlename").show(); $("#div-mod-lastname").show(); $("#div-mod-suffix").show(); $("#div-corporation-name").hide(); $("#mod-birthdate-label").text("Date of birth"); $("#div-mod-gender").show(); $("#div-mod-nationality").show(); $("#div-mod-occupation").show(); $("#div-mod-marital-status").show(); // $('#mod-contact-corporation-div').hide(); // $('#mod-contact-div').show(); $("#div-mod-spouse").show(); $("#div-mod-no-of-children").show(); $("#div-mod-business-company").show(); $("#div-mod-position").show(); $("#div-mod-religion").show(); $("#div-mod-profession").show(); $("#div-corporation-name").hide(); $("#div-mod-age-of-company").hide(); $("#educational_bg_div").show(); } else { $(".children-stepper").hide(); $(".interest-stepper").hide(); $(".interest-list").hide(); $("#div-mod-firstname").hide(); $("#div-mod-middlename").hide(); $("#div-mod-lastname").hide(); $("#div-mod-suffix").hide(); $("#div-corporation-name").show(); $("#mod-birthdate-label").text("Date Established"); $("#div-mod-gender").hide(); $("#div-mod-nationality").hide(); $("#div-mod-occupation").hide(); $("#div-mod-marital-status").hide(); // $('#mod-contact-corporation-div').show(); // $('#mod-contact-div').hide(); $("#div-mod-spouse").hide(); $("#div-mod-no-of-children").hide(); $("#div-mod-business-company").hide(); $("#div-mod-position").hide(); $("#div-mod-religion").hide(); $("#div-mod-profession").hide(); $("#div-mod-date-established").show(); $("#div-mod-age-of-company").show(); $("#educational_bg_div").hide(); } } function addCustomerModalTabSelectedTab(type) { $("#customer-modal-tab .nav-link").removeClass("active"); $("#customer-modal-tab-content .tab-pane").removeClass("show"); $("#customer-modal-tab-content .tab-pane").removeClass("active"); switch (type) { case 1: $("#customer-modal-tab-information").addClass("active"); $("#customer-modal-information").addClass("active"); $("#customer-modal-information").addClass("show"); break; case 2: $("#customer-modal-tab-contact").addClass("active"); $("#customer-modal-contact").addClass("active"); $("#customer-modal-contact").addClass("show"); break; case 3: $("#customer-modal-tab-children").addClass("active"); $("#customer-modal-children").addClass("active"); $("#customer-modal-children").addClass("show"); break; case 4: $("#customer-modal-tab-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("show"); break; case 5: $("#customer-modal-tab-interest").addClass("active"); $("#customer-modal-interest").addClass("active"); $("#customer-modal-interest").addClass("show"); break; } } function uniqId() { return Math.round(new Date().getTime() + Math.random() * 100); } function checkIfEmpty(value, row, index) { if (value == "" || value == "-" || value == null) { return "<span style='color:red;'> (Not Provided) </span>"; } return value; } function getCookie(name) { var match = document.cookie.match(RegExp("(?:^|;\\s*)" + name + "=([^;]*)")); return match ? match[1] : null; } function imageFormatter(value, row, index) { return ( '<img width="50px" height="50px" class="user-image img-circle elevation-2" src="dist/img/thumbnail/' + value + '" />' ); } function initToolTip() { var bootstrapTooltip = $.fn.tooltip.noConflict(); $.fn.bstooltip = bootstrapTooltip; $(".tooltip-me").bstooltip(); } function tableMobileFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='tel:" + value + "'>" + value + "</a>"; } function tableNameFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } //ACTIVE LINK TRIGGER EDIT return "<a href='customer_update_view.php?q=" + row.id + "'>" + value + "</a>"; } function tableEmailFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='mailto:" + value + "'>" + value + "</a>"; } function addDataSourceItem() { var data_source = document.getElementById("data-source-list"); // console.log('asdfasd'); console.log(data_source); const data_source_base = document.querySelector( "#data-source-list-clone tbody tr" ); data_source.appendChild(data_source_base.cloneNode(true)); console.log(data_source) // Generate a unique ID for the select> in the new row. var dataSourceIdDateNow = uniqId(); var newDataSourceCustomerNoId = "data-source-customer-no-" + dataSourceIdDateNow; var newDataSourceDmsId = "data-source-dms-" + dataSourceIdDateNow; var newDataSourceCompanyId = "data-source-company-" + dataSourceIdDateNow; var newDataSourceDealerId = "data-source-dealer-" + dataSourceIdDateNow; var dataSourceItem = []; dataSourceItem[0] = newDataSourceCustomerNoId; dataSourceItem[1] = newDataSourceDmsId; dataSourceItem[2] = newDataSourceCompanyId; dataSourceItem[3] = newDataSourceDealerId; $("#input-modal-customer-no").attr("id", newDataSourceCustomerNoId); $("#" + newDataSourceCustomerNoId) .on("keyup", removeextra) .blur(removeextra); $("#" + newDataSourceCustomerNoId).on("keypress", function (e) { var regex = new RegExp("^[0-9a-zA-Z]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; }); $("#select-modal-dms").attr("id", newDataSourceDmsId).select2({ placeholder: "Select DMS", allowClear: true, }); $("#select-modal-company") .attr("id", newDataSourceCompanyId) .select2({ placeholder: "Select Company", allowClear: true, language: { noResults: function () { return "Select DMS first"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/company/company.php", dataType: "json", delay: 1, data: function (data) { return { search: data.term, // search term dms_id: $("#" + newDataSourceDmsId).val(), apiKey: "3568127986733141", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-preferred-moc").select2({ placeholder: "Select mode of contact", allowClear: true, tags: false, minimumResultsForSearch: -1, language: { noResults: function () { return "Select mode of contact"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/mode_of_contact/mode_of_contact.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "1557741601453763", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-business-company").select2({ placeholder: "Search Company by name, email and mobile", allowClear: true, language: { noResults: function () { return "Search Company by name, email and mobile"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/customer_update/customerv2_update.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "3975247589935894", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#select-modal-dealer") .attr("id", newDataSourceDealerId) .select2({ placeholder: "Select Dealer", allowClear: true, language: { noResults: function () { return "Search or enter dealer name"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/dealer/dealer.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6209267133015033", company_id: $("#" + newDataSourceCompanyId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newDataSourceDmsId).on("change", function (event) { $("#" + newDataSourceCompanyId) .val("") .trigger("change"); }); $("#" + newDataSourceCompanyId).on("change", function (event) { $("#" + newDataSourceDealerId) .val("") .trigger("change"); }); return dataSourceItem; } function addInterestItem() { // CREATE ROW var interest_list = document.getElementById("interest-list"); const interest_list_base = document.querySelector( "#interest-list-clone tbody tr" ); var interestItem = []; interest_list.appendChild(interest_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var InterestIdDateNow = uniqId(); var newInterestCategoryId = "interest-category-" + InterestIdDateNow; var newInterestContentId = "interest-content-" + InterestIdDateNow; interestItem[0] = newInterestCategoryId; interestItem[1] = newInterestContentId; // alert(interestItem.pop(0)); // alert(interestItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category").attr("id", newInterestCategoryId).select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content") .attr("id", newInterestContentId) .select2({ tags: true, placeholder: "Select", allowClear: true, language: { noResults: function () { return "Search or enter interest"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter interest", ajax: { url: "api/interest_hobbies/interest_hobbies.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "5068581874181452", interestCategory: $("#" + newInterestCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newInterestCategoryId).on("select2:select", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); $("#" + newInterestCategoryId).on("select2:unselecting", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); return interestItem; // CREATE ROW } function addAffiliationsItem() { // CREATE ROW var affiliations_list = document.getElementById("affiliations-list"); const affiliations_list_base = document.querySelector( "#affiliations-list-clone tbody tr" ); var affiliationsItem = []; affiliations_list.appendChild(affiliations_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var affiliationsIdDateNow = uniqId(); var newaffiliationsCategoryId = "affiliations-category-" + affiliationsIdDateNow; var newaffiliationsContentId = "affiliations-content-" + affiliationsIdDateNow; affiliationsItem[0] = newaffiliationsCategoryId; affiliationsItem[1] = newaffiliationsContentId; // alert(affiliationsItem.pop(0)); // alert(affiliationsItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category-affiliations") .attr("id", newaffiliationsCategoryId) .select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content-affiliations") .attr("id", newaffiliationsContentId) .select2({ tags: true, placeholder: "Search or enter affiliations", allowClear: true, language: { noResults: function () { return "Search or enter affiliations"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter affiliations", ajax: { url: "api/affiliations/affiliations.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8048636851659915", affiliationsCategory: $("#" + newaffiliationsCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); // $('#' + newaffiliationsCategoryId).on('select2:select', function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); // $('#' + newaffiliationsCategoryId).on("select2:unselecting", function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); return affiliationsItem; // CREATE ROW } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function () { $("#addRowDataSource").click(function () { if ( !checkIfDataSourceIncomplete() && $("#data-source-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data source details first" ); } else { addDataSourceItem(); } }); $("#data-source-list").on("click", ".btnRemoveDataSource", function () { if ($("#data-source-list-table tbody tr").length < 2) { sweetAlertSimple("error", "Oops...", "Need at least 1 data source"); } else { $(this).closest("tr").remove(); } }); $("#addRowChildren").click(function () { var validate_data_children_list = checkIfChildrenIncomplete(); if ( !validate_data_children_list[0] && $("#children-list-table tbody tr").length > 0 ) { sweetAlertSimple("error", "Oops...", "Complete the child details first"); } else if (!validate_data_children_list[1]) { sweetAlertSimple("error", "Oops...", "Children data invalid mobile"); } else { addCustomerChildren(); } }); $("#children-list").on("click", ".btnRemoveChildren", function () { $(this).closest("tr").remove(); }); $("#addRowContactPerson").click(function () { var validate_data_contact_person = checkIfContactPersonIncomplete(); if ( !validate_data_contact_person[0] && $("#contact-person-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data of contact person first" ); } else if (!validate_data_contact_person[1]) { sweetAlertSimple("error", "Oops...", "Contact person invalid email"); } else if (!validate_data_contact_person[2]) { sweetAlertSimple("error", "Oops...", "Contact person invalid mobile"); } else { addCustomerContactPerson(); } }); $("#contact-person-list").on("click", ".btnRemoveContactPerson", function () { $(this).closest("tr").remove(); }); //Date picker $("#mod-birth-date").datetimepicker({ format: "L", }); $("#mod-established-date").datetimepicker({ format: "L", }); $("[data-mask]").inputmask(); $("#modal-customer").on("hidden.bs.modal", function (e) { $(this) .find("input,textarea") .val("") .end() .find("select") .prop("selectedIndex", 0) .find("input[type=checkbox], input[type=radio]") .prop("checked", "") .end(); $(".modal-select2").val("").trigger("change"); }); $("#modal-customer").on("shown.bs.modal", function () { $("input:text:visible:first").focus(); }); $(document).on("wheel", "input[type=number]", function (e) { $(this).blur(); }); $("#mod-nature-of-business").select2({ // tags: true, placeholder: "Select Nature of Business", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/nature_of_business/nature_of_business.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6902545878701742", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-profession").select2({ tags: true, placeholder: "Select Profession", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/profession/profession.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8920139547181378", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-inquiry").select2({ placeholder: "Select Source of Inquiry", allowClear: true, }); $("#mod-dd-gender").select2({ placeholder: "Select Gender", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-marital-status").select2({ placeholder: "Select Marital Status", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-nationality").select2({ placeholder: "Select Nationality", allowClear: true, }); addRowInterest(); addRowAffiliations(); refreshModalReligion(); refreshModalCities(); initToolTip(); }); PK 8F�Z����|� |� customer.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return 'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/customerv2_update.php", type: "POST", dataType: 'json', data: { dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month : filter_month, filter_year :filter_year, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { // console.log($result); $('#total_customer_count').text(result.total_count); $('#new_customer_count').text(result.pending); $('#updated_customer_count').text(result.updated_customer_count); $('#active_customer_count').text(result.total_is_active ); $('#inactive_customer_count').text(result.total_is_inactive ); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_customer_update_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_customer_update_list.php', type: "POST", dataType: 'json', data: { search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month: filter_month, filter_year : filter_year, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-month').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-year').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#customer_action_active').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('active').trigger('change'); }); $('#customer_action_inactive').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('inactive').trigger('change'); }); $('#customer_action_pending').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('pending').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#filter-month').select2({ placeholder: "Month", allowClear: true }) $('#filter-year').select2({ placeholder: "Year", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter document.getElementById("dropdown-filter").addEventListener('click', function(event) { // alert("click outside"); event.stopPropagation(); }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); PK 8F�Z�#ܴ� �� dealer_cu_user_assign_form.jsnu �[��� var force_update = 0; var force_update_reason = ""; function removeextra() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9a-zA-Z]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function removeextranumonly() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9()-]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function getCustomerAllModalData() { var /* Create an object. */ obj = {}, /* Create a variable that references the current object (default → obj). */ ref = obj; /* Iterate over every input. */ $("#modal-customer :input").each(function () { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute("nodetype") == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute("json-modal") == "true") { ref[id] = $(this).val(); } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function sweetAlertSimple(icon, title, text) { // Swal.fire({ // icon: icon, // title: title, // text: text, // allowEnterKey: true // default value // }) toastr.remove(); switch (icon) { case "success": toastr.success(text); break; case "info": toastr.info(text); break; case "warning": toastr.warning(text); break; case "error": toastr.error(text); break; } } function getAllDataSourceTableData() { var $table = $("#data-source-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { var new_header = $(this).html().replace(/\s/g, "_").replace(/\./g, ""); header.push(new_header); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { if (header[i] == "Customer_No") { var key = header[i], value = $(this).find("input").val(); row[key] = value; } else { var key = header[i], value = $(this).find("select").val(); row[key] = value; } }); rows.push(row); }); return rows; } function checkIfDataSourceIncomplete() { rows = getAllDataSourceTableData(); var dataSourceJsonRow = rows; var hasMatch = true; for (var index = 0; index < dataSourceJsonRow.length; ++index) { var dataSourceJson = dataSourceJsonRow[index]; if ( // dataSourceJson.Customer_No == "" || dataSourceJson.DMS == "" || dataSourceJson.Company == "" || dataSourceJson.Dealer == "" ) { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function handleError(xhr, status, error) { //hide loader sweetAlertSimple("error", "Oops...", "Error has occurred, Try again..."); $("#proceed-button").attr("disabled", false); $(".customer-modal-overlay").hide(); force_update = 0; force_update_reason = ""; } function refreshModalCities() { $.ajax({ url: "api/city/city.php", type: "GET", dataType: "json", data: { apiKey: "5881641680981247", }, beforeSend: function () { $("#mod-dd-city-1").prop("disabled", true); $("#mod-dd-city-2").prop("disabled", true); }, success: function (result) { $("#mod-dd-city-1").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-2").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-1").prop("disabled", false); $("#mod-dd-city-2").prop("disabled", false); }, }); } function checkIfChildrenIncomplete() { rows = getAllChildrenTableData(); var childrenJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; for (var index = 0; index < childrenJsonRow.length; ++index) { var childrenJson = childrenJsonRow[index]; if ( childrenJson.Firstname == "" || childrenJson.Lastname == "" || childrenJson.Birthday == "" ) { hasMatch[0] = false; break; } if (!isEmpty(childrenJson.Mobile)) { if (childrenJson.Mobile.length < 10) { hasMatch[1] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllChildrenTableData() { var $table = $("#children-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function isEmail(email) { var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return regex.test(email); } function isEmpty(string) { var flag = false; try { if (string.trim() == "") { flag = true; } else if (string == null) { flag = true; } else if (typeof string === "undefined") { flag = true; } } catch (err) { // console.log(err); flag = true; } return flag; } function checkIfContactPersonIncomplete() { rows = getAllContactPersonTableData(); var contactPersonJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; hasMatch[2] = true; for (var index = 0; index < contactPersonJsonRow.length; ++index) { var contactPersonJson = contactPersonJsonRow[index]; if ( contactPersonJson.Fullname == "" /* || contactPersonJson.Lastname == "" || contactPersonJson.Mobile == ""*/ ) { hasMatch[0] = false; break; } if (contactPersonJson.Email != "") { if (!isEmail(contactPersonJson.Email)) { hasMatch[1] = false; break; } } if (!isEmpty(contactPersonJson.Mobile)) { if (contactPersonJson.Mobile.length < 10) { hasMatch[2] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllContactPersonTableData() { var $table = $("#contact-person-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function addCustomerChildren() { var children_list = document.getElementById("children-list"); const children_list_base = document.querySelector( "#children-list-clone tbody tr" ); children_list.appendChild(children_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var ChildrenIdDateNow = uniqId(); var newChildrenFirstnameId = "children-firstname-" + ChildrenIdDateNow; var newChildrenLastnameId = "children-lastname-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "div-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "append-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayId = "children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "children-birthday-div-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "children-birthday-append-" + ChildrenIdDateNow; var newChildrenMobileId = "children-mobile-append-" + ChildrenIdDateNow; var item = []; item[0] = newChildrenFirstnameId; item[1] = newChildrenLastnameId; item[2] = newChildrenBirthdayId; item[3] = newChildrenMobileId; $("#mod-children-firstname").attr("id", newChildrenFirstnameId); $("#mod-children-lastname").attr("id", newChildrenLastnameId); $("#mod-children-mobile").attr("id", newChildrenMobileId); $("#mod-children-birthdate") .attr("id", newChildrenBirthdayId) .data("target", "#" + newChildrenBirthdayDivId) .inputmask(); $("#mod-children-birthdate-append") .attr("id", newChildrenBirthdayAppendId) .data("target", "#" + newChildrenBirthdayDivId); $("#mod-children-birthdate-div") .attr("id", newChildrenBirthdayDivId) .datetimepicker({ format: "L", }); return item; } function addCustomerContactPerson() { var contact_person_list = document.getElementById("contact-person-list"); const contact_person_list_base = document.querySelector( "#contact-person-list-clone tbody tr" ); contact_person_list.appendChild(contact_person_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var contactPersonIdDateNow = uniqId(); var newContactPersonFullnameId = "contact-person-fullname-" + contactPersonIdDateNow; var newContactPersonFirstnameId = "contact-person-firstname-" + contactPersonIdDateNow; var newContactPersonLastnameId = "contact-person-lastname-" + contactPersonIdDateNow; var newContactPersonEmailId = "contact-person-email-" + contactPersonIdDateNow; var newContactPersonMobileId = "contact-person-mobile-" + contactPersonIdDateNow; var item = []; item[0] = newContactPersonFullnameId; item[1] = newContactPersonEmailId; item[2] = newContactPersonMobileId; $("#modal-contact-person-fullname").attr("id", newContactPersonFullnameId); $("#modal-contact-person-email").attr("id", newContactPersonEmailId); $("#modal-contact-person-mobile").attr("id", newContactPersonMobileId); return item; } function addRowInterest() { $("#addRow").click(function () { if ( !checkIfInterestIncomplete() && $("#interest-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the interest/hobbies details first" ); } else { addInterestItem(); } }); $("#interest-list").on("click", ".btnRemove", function () { $(this).closest("tr").remove(); }); } function getAllInterestTableData() { var $table = $("#interest-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfInterestIncomplete() { rows = getAllInterestTableData(); var interestJsonRow = rows; var hasMatch = true; for (var index = 0; index < interestJsonRow.length; ++index) { var interestJson = interestJsonRow[index]; if (interestJson.Category == "" || interestJson.Interest == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function addRowAffiliations() { $("#addRowAffiliations").click(function () { if ( !checkIfAffiliationsIncomplete() && $("#affiliations-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the affiliation details first" ); } else { addAffiliationsItem(); } }); $("#affiliations-list").on("click", ".btnRemoveAffiliations", function () { $(this).closest("tr").remove(); }); } function getAllAffiliationsTableData() { var $table = $("#affiliations-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html().replace(/\s/g, "_").replace(/\./g, "")); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfAffiliationsIncomplete() { rows = getAllAffiliationsTableData(); var jsonRow = rows; var hasMatch = true; for (var index = 0; index < jsonRow.length; ++index) { var json = jsonRow[index]; if (json.Category == "" || json.Affiliations == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function refreshModalReligion() { $.ajax({ url: "api/religion/religion.php", method: "POST", data: { apiKey: "2011315786548487", }, cache: false, beforeSend: function () {}, success: function (result) { var obj = jQuery.parseJSON(result); $("#mod-dd-religion").select2({ tags: true, placeholder: "Select Religion", allowClear: true, data: obj, }); }, }); } function resetCustomerModal() { $("#mod-dd-nationality").val("608").trigger("change"); $("#interest-list-table > tbody").empty(); $("#affiliations-list-table > tbody").empty(); $("#contact-person-list-table > tbody").empty(); $("#children-list-table > tbody").empty(); $("#data-source-list-table > tbody").empty(); $("#educational-bg-list-table > tbody").empty(); $("#car-clubs-list-table > tbody").empty(); $("#unit-association-list-table > tbody").empty(); $("#political-clubs-list-table > tbody").empty(); $("#network-marketing-list-table > tbody").empty(); $("#media-publications-list-table > tbody").empty(); $("#sme-groups-list-table > tbody").empty(); $("#fraternities-sororities-list-table > tbody").empty(); $("#facebook-groups-list-table > tbody").empty(); $("#celebrity-influencers-list-table > tbody").empty(); addCustomerModalTabSelectedTab(1); } function checkFieldsModal(isIndividual) { if (isIndividual) { $(".children-stepper").show(); $(".interest-stepper").show(); $(".interest-list").show(); $("#div-mod-firstname").show(); $("#div-mod-middlename").show(); $("#div-mod-lastname").show(); $("#div-mod-suffix").show(); $("#div-corporation-name").hide(); $("#mod-birthdate-label").text("Date of birth"); $("#div-mod-gender").show(); $("#div-mod-nationality").show(); $("#div-mod-occupation").show(); $("#div-mod-marital-status").show(); // $('#mod-contact-corporation-div').hide(); // $('#mod-contact-div').show(); $("#div-mod-spouse").show(); $("#div-mod-no-of-children").show(); $("#div-mod-business-company").show(); $("#div-mod-position").show(); $("#div-mod-religion").show(); $("#div-mod-profession").show(); $("#div-corporation-name").hide(); $("#div-mod-age-of-company").hide(); $("#educational_bg_div").show(); } else { $(".children-stepper").hide(); $(".interest-stepper").hide(); $(".interest-list").hide(); $("#div-mod-firstname").hide(); $("#div-mod-middlename").hide(); $("#div-mod-lastname").hide(); $("#div-mod-suffix").hide(); $("#div-corporation-name").show(); $("#mod-birthdate-label").text("Date Established"); $("#div-mod-gender").hide(); $("#div-mod-nationality").hide(); $("#div-mod-occupation").hide(); $("#div-mod-marital-status").hide(); // $('#mod-contact-corporation-div').show(); // $('#mod-contact-div').hide(); $("#div-mod-spouse").hide(); $("#div-mod-no-of-children").hide(); $("#div-mod-business-company").hide(); $("#div-mod-position").hide(); $("#div-mod-religion").hide(); $("#div-mod-profession").hide(); $("#div-mod-date-established").show(); $("#div-mod-age-of-company").show(); $("#educational_bg_div").hide(); } } function addCustomerModalTabSelectedTab(type) { $("#customer-modal-tab .nav-link").removeClass("active"); $("#customer-modal-tab-content .tab-pane").removeClass("show"); $("#customer-modal-tab-content .tab-pane").removeClass("active"); switch (type) { case 1: $("#customer-modal-tab-information").addClass("active"); $("#customer-modal-information").addClass("active"); $("#customer-modal-information").addClass("show"); break; case 2: $("#customer-modal-tab-contact").addClass("active"); $("#customer-modal-contact").addClass("active"); $("#customer-modal-contact").addClass("show"); break; case 3: $("#customer-modal-tab-children").addClass("active"); $("#customer-modal-children").addClass("active"); $("#customer-modal-children").addClass("show"); break; case 4: $("#customer-modal-tab-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("show"); break; case 5: $("#customer-modal-tab-interest").addClass("active"); $("#customer-modal-interest").addClass("active"); $("#customer-modal-interest").addClass("show"); break; } } function uniqId() { return Math.round(new Date().getTime() + Math.random() * 100); } function checkIfEmpty(value, row, index) { if (value == "" || value == "-" || value == null) { return "<span style='color:red;'> (Not Provided) </span>"; } return value; } function getCookie(name) { var match = document.cookie.match(RegExp("(?:^|;\\s*)" + name + "=([^;]*)")); return match ? match[1] : null; } function imageFormatter(value, row, index) { return ( '<img width="50px" height="50px" class="user-image img-circle elevation-2" src="dist/img/thumbnail/' + value + '" />' ); } function initToolTip() { var bootstrapTooltip = $.fn.tooltip.noConflict(); $.fn.bstooltip = bootstrapTooltip; $(".tooltip-me").bstooltip(); } function tableMobileFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='tel:" + value + "'>" + value + "</a>"; } function tableNameFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } //ACTIVE LINK TRIGGER EDIT return "<a href='sm-dealer-view?q=" + row.ref_header_link + "'>" + value + "</a>"; } function tableEmailFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } // return "<a href='mailto:" + value + "'>" + value + "</a>"; return value; } function addDataSourceItem() { var data_source = document.getElementById("data-source-list"); const data_source_base = document.querySelector( "#data-source-list-clone tbody tr" ); data_source.appendChild(data_source_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var dataSourceIdDateNow = uniqId(); var newDataSourceCustomerNoId = "data-source-customer-no-" + dataSourceIdDateNow; var newDataSourceDmsId = "data-source-dms-" + dataSourceIdDateNow; var newDataSourceCompanyId = "data-source-company-" + dataSourceIdDateNow; var newDataSourceDealerId = "data-source-dealer-" + dataSourceIdDateNow; var dataSourceItem = []; dataSourceItem[0] = newDataSourceCustomerNoId; dataSourceItem[1] = newDataSourceDmsId; dataSourceItem[2] = newDataSourceCompanyId; dataSourceItem[3] = newDataSourceDealerId; $("#input-modal-customer-no").attr("id", newDataSourceCustomerNoId); $("#" + newDataSourceCustomerNoId) .on("keyup", removeextra) .blur(removeextra); $("#" + newDataSourceCustomerNoId).on("keypress", function (e) { var regex = new RegExp("^[0-9a-zA-Z]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; }); $("#select-modal-dms").attr("id", newDataSourceDmsId).select2({ placeholder: "Select DMS", allowClear: true, }); $("#select-modal-company") .attr("id", newDataSourceCompanyId) .select2({ placeholder: "Select Company", allowClear: true, language: { noResults: function () { return "Select DMS first"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/company/company.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term dms_id: $("#" + newDataSourceDmsId).val(), apiKey: "3568127986733141", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-preferred-moc").select2({ placeholder: "Select mode of contact", allowClear: true, tags: false, minimumResultsForSearch: -1, language: { noResults: function () { return "Select mode of contact"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/mode_of_contact/mode_of_contact.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "1557741601453763", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-business-company").select2({ placeholder: "Search Company by name, email and mobile", allowClear: true, language: { noResults: function () { return "Search Company by name, email and mobile"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/customer_update/customerv2_update.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "3975247589935894", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#select-modal-dealer") .attr("id", newDataSourceDealerId) .select2({ placeholder: "Select Dealer", allowClear: true, language: { noResults: function () { return "Search or enter dealer name"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/dealer/dealer.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6209267133015033", company_id: $("#" + newDataSourceCompanyId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newDataSourceDmsId).on("change", function (event) { $("#" + newDataSourceCompanyId) .val("") .trigger("change"); }); $("#" + newDataSourceCompanyId).on("change", function (event) { $("#" + newDataSourceDealerId) .val("") .trigger("change"); }); return dataSourceItem; } function addInterestItem() { // CREATE ROW var interest_list = document.getElementById("interest-list"); const interest_list_base = document.querySelector( "#interest-list-clone tbody tr" ); var interestItem = []; interest_list.appendChild(interest_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var InterestIdDateNow = uniqId(); var newInterestCategoryId = "interest-category-" + InterestIdDateNow; var newInterestContentId = "interest-content-" + InterestIdDateNow; interestItem[0] = newInterestCategoryId; interestItem[1] = newInterestContentId; // alert(interestItem.pop(0)); // alert(interestItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category").attr("id", newInterestCategoryId).select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content") .attr("id", newInterestContentId) .select2({ tags: true, placeholder: "Select", allowClear: true, language: { noResults: function () { return "Search or enter interest"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter interest", ajax: { url: "api/interest_hobbies/interest_hobbies.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "5068581874181452", interestCategory: $("#" + newInterestCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newInterestCategoryId).on("select2:select", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); $("#" + newInterestCategoryId).on("select2:unselecting", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); return interestItem; // CREATE ROW } function addAffiliationsItem() { // CREATE ROW var affiliations_list = document.getElementById("affiliations-list"); const affiliations_list_base = document.querySelector( "#affiliations-list-clone tbody tr" ); var affiliationsItem = []; affiliations_list.appendChild(affiliations_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var affiliationsIdDateNow = uniqId(); var newaffiliationsCategoryId = "affiliations-category-" + affiliationsIdDateNow; var newaffiliationsContentId = "affiliations-content-" + affiliationsIdDateNow; affiliationsItem[0] = newaffiliationsCategoryId; affiliationsItem[1] = newaffiliationsContentId; // alert(affiliationsItem.pop(0)); // alert(affiliationsItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category-affiliations") .attr("id", newaffiliationsCategoryId) .select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content-affiliations") .attr("id", newaffiliationsContentId) .select2({ tags: true, placeholder: "Search or enter affiliations", allowClear: true, language: { noResults: function () { return "Search or enter affiliations"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter affiliations", ajax: { url: "api/affiliations/affiliations.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8048636851659915", affiliationsCategory: $("#" + newaffiliationsCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); // $('#' + newaffiliationsCategoryId).on('select2:select', function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); // $('#' + newaffiliationsCategoryId).on("select2:unselecting", function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); return affiliationsItem; // CREATE ROW } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function () { $("#addRowDataSource").click(function () { if ( !checkIfDataSourceIncomplete() && $("#data-source-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data source details first" ); } else { addDataSourceItem(); } }); $("#data-source-list").on("click", ".btnRemoveDataSource", function () { if ($("#data-source-list-table tbody tr").length < 2) { sweetAlertSimple("error", "Oops...", "Need at least 1 data source"); } else { $(this).closest("tr").remove(); } }); $("#addRowChildren").click(function () { var validate_data_children_list = checkIfChildrenIncomplete(); if ( !validate_data_children_list[0] && $("#children-list-table tbody tr").length > 0 ) { sweetAlertSimple("error", "Oops...", "Complete the child details first"); } else if (!validate_data_children_list[1]) { sweetAlertSimple("error", "Oops...", "Children data invalid mobile"); } else { addCustomerChildren(); } }); $("#children-list").on("click", ".btnRemoveChildren", function () { $(this).closest("tr").remove(); }); $("#addRowContactPerson").click(function () { var validate_data_contact_person = checkIfContactPersonIncomplete(); if ( !validate_data_contact_person[0] && $("#contact-person-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data of contact person first" ); } else if (!validate_data_contact_person[1]) { sweetAlertSimple("error", "Oops...", "Contact person invalid email"); } else if (!validate_data_contact_person[2]) { sweetAlertSimple("error", "Oops...", "Contact person invalid mobile"); } else { addCustomerContactPerson(); } }); $("#contact-person-list").on("click", ".btnRemoveContactPerson", function () { $(this).closest("tr").remove(); }); //Date picker $("#mod-birth-date").datetimepicker({ format: "L", }); $("#mod-established-date").datetimepicker({ format: "L", }); $("[data-mask]").inputmask(); $("#modal-customer").on("hidden.bs.modal", function (e) { $(this) .find("input,textarea") .val("") .end() .find("select") .prop("selectedIndex", 0) .find("input[type=checkbox], input[type=radio]") .prop("checked", "") .end(); $(".modal-select2").val("").trigger("change"); }); $("#modal-customer").on("shown.bs.modal", function () { $("input:text:visible:first").focus(); }); $(document).on("wheel", "input[type=number]", function (e) { $(this).blur(); }); $("#mod-nature-of-business").select2({ // tags: true, placeholder: "Select Nature of Business", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/nature_of_business/nature_of_business.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6902545878701742", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-profession").select2({ tags: true, placeholder: "Select Profession", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/profession/profession.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8920139547181378", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-inquiry").select2({ placeholder: "Select Source of Inquiry", allowClear: true, }); $("#mod-dd-gender").select2({ placeholder: "Select Gender", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-marital-status").select2({ placeholder: "Select Marital Status", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-nationality").select2({ placeholder: "Select Nationality", allowClear: true, }); addRowInterest(); addRowAffiliations(); refreshModalReligion(); refreshModalCities(); initToolTip(); }); PK 8F�Z ��Y�� �� sm_dealer_view_cu.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return 'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ // url: "api/customer/customerv2_update.php", url: "api/customer_update/sm_dealer_view_assigned_cu.php", type: "POST", dataType: 'json', data: { ref_num_header: ref_num_header, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month : filter_month, filter_year : filter_year, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { // console.log($result); $('#total_customer_count').text(result.total_icu_assigned); $('#pending_customer_count').text(result.pending_customer_count); $('#updated_customer_count').text(result.updated_customer_count); $('#active_customer_count').text(result.total_is_active); $('#inactive_customer_count').text(result.total_is_inactive); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_sm_dealer_view_customer_update_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_sm_dealer_view_customer_update_list.php', type: "POST", dataType: 'json', data: { ref_num_header:ref_num_header, search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").hide();//show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { ref_num_header: ref_num_header, search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month : filter_month, filter_year : filter_year, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-month').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-year').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_pending').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('pending').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_active').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('active').trigger('change'); }); $('#customer_action_inactive').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('inactive').trigger('change'); }); $('#customer_action_pending').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('pending').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#filter-month').select2({ placeholder: "Month", allowClear: true }) $('#filter-year').select2({ placeholder: "Year", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // // alert("click outside"); // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#filter-month').off('change.mychange'); $('#filter-year').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#filter-month').val('').trigger('change') $('#filter-year').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); $(document).on('mousedown', ".is_active", function() { // Store the current value as the old value $(this).data("prev", $(this).val()); // console.log($(this).data("prev", $(this).val())) }); $(document).on('change', ".is_active", function() { let oldValue = $(this).data("prev"); if ($(this).val() =='0') { Swal.fire({ icon: 'warning', title: 'Oops!', text: "Status field is required.", allowEnterKey: true // default value }); $(this).val(oldValue); return false; // Prevent further execution if validation fails } Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { let st = $(this).val();//($(this).is(':checked') ? 1 : 0); $.ajax({ url: "api/customer_update/sm_dealer_view_assigned_cu.php", type: "POST", dataType: 'json', data: { apiKey: setpy,val: $(this).attr("data-id"),attr:st },success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: result.msg, allowEnterKey: true // default value }); // location.reload(); setTimeout(()=>{ Swal.close() ; location.reload(); },2000); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } } }); } else { $(this).val(oldValue); } }); }); const goBack = () => { window.history.back(); } PK 8F�Z.��:�� �� dealer_assign_user.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return '';//'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''//'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: '8666264351338448' }, beforeSend: function() {}, success: function(result) { // a=result.total_icu.replace(/\,/g,''); // 1125, but a string, so convert it to number // total_avail_inactive=parseInt(a,10); // $("#no_assign").attr({ // "max" : total_avail_inactive, // "min" : 1 // }); // $('#total_customer_count').text(result.total_icu); // if(result.total_icu ==0) // { // $("#sl_company").attr('disabled', true); // $("#btn-submit-manually").attr('disabled', true); // } // else // { // $("#sl_company").attr('disabled', false); // $("#btn-submit-manually").attr('disabled', false); // } // $('#new_customer_count').text(result.new_customer_count); // $('#updated_customer_count').text(result.updated_customer_count); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { // url: 'app/table/bt_dealer_assignment_update_list.php' url: 'app/table/bt_dealer_assignment_user_update_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_customer_update_list.php', type: "POST", dataType: 'json', data: { search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // // alert("click outside"); // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); function users(){ $("#sl_dealer").empty(); $("#sl_dealer").prop( "disabled", false ); $.ajax({ url: "api/customer_update/assign_dealer_user.php", type: "POST", dataType: 'json', data: {apiKey: apy,cdi:ucdi}, beforeSend: function() {}, success: function(result) { $("#sl_user").attr('required',true); $('#sl_user').append($('<option value=""></option>').text('Select User')); $.each(result, function(key, value) { $('#sl_user') .append($("<option></option>") .attr("value",value.id) .text(value.text)); }); } }); }users(); // function company() { // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: 'mRLAZ8te7cnv', // }, // beforeSend: function() {}, // success: function(result) { // $("#sl_company").val(''); // $.each(result, function(key, value) { // $('#sl_company') // .append($("<option></option>") // .attr("value",value.id) // .text(value.text)); // }); // } // }); // } // company(); // $("#sl_company").on('change', function(){ // $("#sl_dealer").empty(); // if($(this).val()!=''){ // $("#sl_dealer").prop( "disabled", false ); // } // else // { // $("#sl_dealer").prop( "disabled", true ); // } // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: 'f5AHTwg8MF9c', // cid:$(this).val() // }, // beforeSend: function() {}, // success: function(result) { // $.each(result, function(key, value) { // $('#sl_dealer') // .append($("<option></option>") // .attr("value",value.id) // .text(value.text)); // }); $("#sl_dealer").val(''); // } // }); // }); // $("#sl_dealer").on('change', function(){ // $("#sl_user").empty(); // if($(this).val()!=''){ // $("#sl_user").prop( "disabled", false ); // } // else // { // $("#sl_user").prop( "disabled", true ); // } // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: 'L9T6kZfc8K4D', // cdi:$(this).val() // }, // beforeSend: function() {}, // success: function(result) { // $.each(result, function(key, value) { // $('#sl_user') // .append($("<option></option>") // .attr("value",value.id) // .text(value.text)); // }); // $("#sl_user").val(''); // } // }); // }); // $("#sl_dealer").on('change', function(){ // $("#no_assign").val(''); // if($(this).val()!=''){ // $("#no_assign").prop( "disabled", false ); // } // else // { // $("#no_assign").prop( "disabled", true ); // } // }); // function autoAssign(apy) // { // $("#spinner-loader").show(); // $('.fieldset').prop('disabled', true) // $(":button").prop('disabled',true); // $("#assign_to_dealers").hide(); // $("#spinner-loader").show(); // $.ajax({ // url: "api/customer_update/assign_dealer.php",//"api/customer_update/customerv2_update.php", // type: "POST", // dataType: 'json', // data: { // apiKey: apy, // // cdi:$(this).val() // }, // // beforeSend: function() {}, // // beforeSend: function(xhr) { // // // Show loader before the request starts // // $("#spinner-loader").show(); // // $('.fieldset').prop('disabled', true); // // $(":button").prop('disabled', true); // // $("#assign_to_dealers").hide(); // // // Track progress // // // Check if xhr.upload is defined before adding the event listener // // if (xhr.upload) { // // xhr.upload.addEventListener("progress", function(evt) { // // if (evt.lengthComputable) { // // var percentComplete = (evt.loaded / evt.total) * 100; // // console.log(percentComplete + "%"); // // // Update the progress bar or display the percentage as needed // // } // // }, false); // // } // // }, // complete: function(){ // $("#spinner-loader").hide(); // $('.fieldset').prop('disabled', false) // $(":button").prop('disabled',false); // $("#assign_to_dealers").show(); // }, // success: function(result) { // if(result.status==0){ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // if(result.status==1){ // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.no_assign+' '+result.msg+' '+result.no_of_dealers+' '+result.dealer, // allowEnterKey: true // default value // }); // location.reload(); // } // } // }); // } // function resetAssign(apy) // { // Swal.fire({ // title: 'Are you sure?', // text: "You are about to execute this command. Do you want to proceed?", // icon: 'warning', // showCancelButton: true, // confirmButtonColor: '#3085d6', // cancelButtonColor: '#d33', // confirmButtonText: 'Yes, execute it!' // }).then((result) => { // if (result.isConfirmed) { // $("#spinner-loader").show(); // $('.fieldset').prop('disabled', true) // $(":button").prop('disabled',true); // $("#reset-assignment").hide(); // $("#spinner-loader-purple").show(); // $.ajax({ // url: "api/customer_update/assign_dealer.php",//"api/customer_update/customerv2_update.php", // type: "POST", // dataType: 'json', // data: { // apiKey: apy, // // cdi:$(this).val() // }, // // beforeSend: function() {}, // // beforeSend: function(xhr) { // // }, // complete: function(){ // $("#spinner-loader-purple").hide(); // $('.fieldset').prop('disabled', false) // $(":button").prop('disabled',false); // $("#reset-assignment").show(); // }, // success: function(result) { // if(result.status==0){ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // if(result.status==1){ // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.no_assign+' '+result.msg+' '+result.no_of_dealers+' '+result.dealer, // allowEnterKey: true // default value // }); // location.reload(); // } // } // }); // } // }); // } // $(document).on('change', '.usr-id', function() { // let hdr = $(this).closest('tr').find('.hdr').val(); // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: $("#ausr-py").val(), // uid:$(this).val(), // hdr:hdr, // }, // success: function(result) { // if(result.status==1) // { // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.msg, // allowEnterKey: true // default value // }); // setTimeout(()=>{ // // location.reload(); // },3000); // }else{ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // } // }); // }); // function relodMdl() // { // location.reload(); // } // function loadDealers(apy){ // $.ajax({ // url: 'api/customer_update/assign_dealer.php', // method: 'POST', // data: {apiKey:apy }, // success: function(response) { // $('#table_dlr tbody').empty(); // // Parse JSON response // var dealers = JSON.parse(response); // // Loop through each dealer object and append to the table // $.each(dealers, function(index, dealer) { // var row = $("<tr>"); // row.append($("<td>").text(index+1)); // row.append($("<td>").text(dealer.text)); // row.append($("<td>").html("<input type='checkbox' class='chk-active-dlr' "+dealer.check+" value='" + dealer.id + "'/>")); // $('#table_dlr tbody').append(row); // }); // $('#table_dlr').DataTable({ // // "scrollY": "300px", // Set fixed height with scrolling // // "lengthMenu": false,//remove select result // "paging": true, // Enable pagination // "searching": true, // Enable search bar // "pagingType": "simple_numbers", // Use buttons for pagination // "language": { // "paginate": { // "previous": "<", // "next": ">" // } // } // }); // }, // error: function(xhr, status, error) { // console.error(error); // Log any errors // } // }); // } // $("#btn-submit-manually").on('click', function(e) { // e.preventDefault(); // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: $("#apiy").val(), // cm: $("#sl_company").val(), // dlr: $("#sl_dealer").val(), // usr: $("#sl_user").val(), // nos: $("#no_assign").val() // }, // success: function(result) { // if(result.status==1) // { // setTimeout(()=>{ // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.nos+' '+result.msg+' '+result.dealer, // allowEnterKey: true // default value // }); // location.reload(); // },3000); // }else{ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // } // }); // }); $(document).ready(function(){ function count_avl_cu() { $("#sl_source").attr('disabled',false); $("#sl_user").attr('disabled',false); $("#btn-submit-manually").attr('disabled',false); $.ajax({ url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: '8666264351338448' }, beforeSend: function() {}, success: function(result) { if(result.total_icu_assigned<=0) { $("#sl_source").attr('disabled',true); $("#sl_user").attr('disabled',true); $("#btn-submit-manually").attr('disabled',true); } else{ $('#total_customer_count').text("/"+ result.total_icu_assigned); a=result.total_icu_assigned.replace(/\,/g,''); total_avail_inactive=parseInt(a,10); if(total_avail_inactive ==0) { $("#no_assign").attr('disabled', true); $("#btn-submit-manually").attr('disabled', true); } else { $("#no_assign").attr({ "max" : total_avail_inactive, "min" : 1 }); $("#sl_user").attr('disabled',false); // $("#no_assign").attr('disabled', false); // $("#btn-submit-manually").attr('disabled', false); } } } }); } count_avl_cu(); function source() { $.ajax({ url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: spy }, beforeSend: function() {}, success: function(result) { $.each(result, function(key, value) { $('#sl_source') .append($("<option></option>") .attr("value",value.id) .text(value.text)); }); } }); } source(); $("#sl_source").on('change', function(){ $("#no_assign").attr('disabled', true); $("#btn-submit-manually").attr('disabled', true); $("#sl_user").attr('disabled', true); $.ajax({ url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: stpy, hdr:$(this).val() }, beforeSend: function() {}, success: function(result) { // a=result.total_avl_customer.replace(/\,/g,''); // total_available_customer=parseInt(a,10); if(parseInt(result.total_avl_customer)>0) { $("#no_assign").attr('disabled', false); $("#btn-submit-manually").attr('disabled', false); $("#sl_user").attr('disabled', false); } } }); }); $("#btn-submit-manually").on('click', function(e) { $("#btn-submit-manually").attr('disabled', true); e.preventDefault(); let shouldSubmit = true; Swal.fire({ title: 'Are you sure?', text: "You are about to assign a customer list to this user. Please ensure that the selected user is under your supervision or within your group under the same dealer to avoid conflicts arising from incorrect assignments.", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { // Check if the select box has a selected option if ($("#sl_user option:selected").val() === "") { Swal.fire({ icon: 'warning', title: 'Oops!', text: "User field is required.", allowEnterKey: true // default value }); $("#sl_user").focus(); $("#btn-submit-manually").attr('disabled', false); shouldSubmit = false; return false; } // If shouldSubmit is true, proceed with AJAX call if (shouldSubmit) { $.ajax({ url: "api/customer_update/assign_dealer_user.php", type: "POST", dataType: 'json', data: { apiKey: xtpy, hdr: $("#sl_source").val(), nos: $("#no_assign").val(), uid: $("#sl_user").val(), }, beforeSend: function() {}, success: function(response) { if(response.status == 1) { Swal.fire({ icon: 'success', title: 'Success!', text: response.msg, allowEnterKey: true // default value }); $("#btn-submit-manually").attr('disabled', false); setTimeout(() => { Swal.close(); location.reload(); }, 2500); } else { Swal.fire({ icon: 'warning', title: 'Oops!', text: response.msg, allowEnterKey: true // default value }); } } }); } } }); }); // $("#btn-submit-manually").on('click', function(e) { // e.preventDefault(); // let shouldSubmit = true; // Swal.fire({ // title: 'Are you sure?', // text: "You are about to assign a customer list to this user. Please ensure that the selected user is under your supervision or within your group under the same dealer to avoid conflicts arising from incorrect assignments.", // icon: 'warning', // showCancelButton: true, // confirmButtonColor: '#3085d6', // cancelButtonColor: '#d33', // confirmButtonText: 'Yes, execute it!' // }).then((result) => { // if (result.isConfirmed) { // if($("#sl_user").val() === "") // { // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: "User field is required.", // allowEnterKey: true // default value // }); // // users(); // // location.reload(); // $("#sl_user").focus(); // shouldSubmit = false; // return false; // } // $.ajax({ // url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", // type: "POST", // dataType: 'json', // data: { // apiKey: xtpy, // hdr: $("#sl_source").val(), // nos: $("#no_assign").val(), // uid: $("#sl_user").val(), // }, // beforeSend: function() {}, // success: function(response) { // if(response.status==1) // { // Swal.fire({ // icon: 'success', // title: 'Success!', // text: response.msg, // allowEnterKey: true // default value // }); // setTimeout(()=>{ // Swal.close() ; // location.reload(); // },2500); // }else{ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: response.msg, // allowEnterKey: true // default value // }); // } // } // }); // } // }); // }); }); const goBack = () => { window.history.back(); } PK 8F�Z 68U�� �� u_customer_assigned_user_form.jsnu �[��� var force_update = 0; var force_update_reason = ""; function removeextra() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9a-zA-Z]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function removeextranumonly() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9()-]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function getCustomerAllModalData() { var /* Create an object. */ obj = {}, /* Create a variable that references the current object (default → obj). */ ref = obj; /* Iterate over every input. */ $("#modal-customer :input").each(function () { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute("nodetype") == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute("json-modal") == "true") { ref[id] = $(this).val(); } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function sweetAlertSimple(icon, title, text) { // Swal.fire({ // icon: icon, // title: title, // text: text, // allowEnterKey: true // default value // }) toastr.remove(); switch (icon) { case "success": toastr.success(text); break; case "info": toastr.info(text); break; case "warning": toastr.warning(text); break; case "error": toastr.error(text); break; } } function getAllDataSourceTableData() { var $table = $("#data-source-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { var new_header = $(this).html().replace(/\s/g, "_").replace(/\./g, ""); header.push(new_header); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { if (header[i] == "Customer_No") { var key = header[i], value = $(this).find("input").val(); row[key] = value; } else { var key = header[i], value = $(this).find("select").val(); row[key] = value; } }); rows.push(row); }); return rows; } function checkIfDataSourceIncomplete() { rows = getAllDataSourceTableData(); var dataSourceJsonRow = rows; var hasMatch = true; for (var index = 0; index < dataSourceJsonRow.length; ++index) { var dataSourceJson = dataSourceJsonRow[index]; if ( // dataSourceJson.Customer_No == "" || dataSourceJson.DMS == "" || dataSourceJson.Company == "" || dataSourceJson.Dealer == "" ) { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function handleError(xhr, status, error) { //hide loader sweetAlertSimple("error", "Oops...", "Error has occurred, Try again..."); $("#proceed-button").attr("disabled", false); $(".customer-modal-overlay").hide(); force_update = 0; force_update_reason = ""; } function refreshModalCities() { $.ajax({ url: "api/city/city.php", type: "GET", dataType: "json", data: { apiKey: "5881641680981247", }, beforeSend: function () { $("#mod-dd-city-1").prop("disabled", true); $("#mod-dd-city-2").prop("disabled", true); }, success: function (result) { $("#mod-dd-city-1").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-2").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-1").prop("disabled", false); $("#mod-dd-city-2").prop("disabled", false); }, }); } function checkIfChildrenIncomplete() { rows = getAllChildrenTableData(); var childrenJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; for (var index = 0; index < childrenJsonRow.length; ++index) { var childrenJson = childrenJsonRow[index]; if ( childrenJson.Firstname == "" || childrenJson.Lastname == "" || childrenJson.Birthday == "" ) { hasMatch[0] = false; break; } if (!isEmpty(childrenJson.Mobile)) { if (childrenJson.Mobile.length < 10) { hasMatch[1] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllChildrenTableData() { var $table = $("#children-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function isEmail(email) { var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return regex.test(email); } function isEmpty(string) { var flag = false; try { if (string.trim() == "") { flag = true; } else if (string == null) { flag = true; } else if (typeof string === "undefined") { flag = true; } } catch (err) { // console.log(err); flag = true; } return flag; } function checkIfContactPersonIncomplete() { rows = getAllContactPersonTableData(); var contactPersonJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; hasMatch[2] = true; for (var index = 0; index < contactPersonJsonRow.length; ++index) { var contactPersonJson = contactPersonJsonRow[index]; if ( contactPersonJson.Fullname == "" /* || contactPersonJson.Lastname == "" || contactPersonJson.Mobile == ""*/ ) { hasMatch[0] = false; break; } if (contactPersonJson.Email != "") { if (!isEmail(contactPersonJson.Email)) { hasMatch[1] = false; break; } } if (!isEmpty(contactPersonJson.Mobile)) { if (contactPersonJson.Mobile.length < 10) { hasMatch[2] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllContactPersonTableData() { var $table = $("#contact-person-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function addCustomerChildren() { var children_list = document.getElementById("children-list"); const children_list_base = document.querySelector( "#children-list-clone tbody tr" ); children_list.appendChild(children_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var ChildrenIdDateNow = uniqId(); var newChildrenFirstnameId = "children-firstname-" + ChildrenIdDateNow; var newChildrenLastnameId = "children-lastname-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "div-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "append-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayId = "children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "children-birthday-div-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "children-birthday-append-" + ChildrenIdDateNow; var newChildrenMobileId = "children-mobile-append-" + ChildrenIdDateNow; var item = []; item[0] = newChildrenFirstnameId; item[1] = newChildrenLastnameId; item[2] = newChildrenBirthdayId; item[3] = newChildrenMobileId; $("#mod-children-firstname").attr("id", newChildrenFirstnameId); $("#mod-children-lastname").attr("id", newChildrenLastnameId); $("#mod-children-mobile").attr("id", newChildrenMobileId); $("#mod-children-birthdate") .attr("id", newChildrenBirthdayId) .data("target", "#" + newChildrenBirthdayDivId) .inputmask(); $("#mod-children-birthdate-append") .attr("id", newChildrenBirthdayAppendId) .data("target", "#" + newChildrenBirthdayDivId); $("#mod-children-birthdate-div") .attr("id", newChildrenBirthdayDivId) .datetimepicker({ format: "L", }); return item; } function addCustomerContactPerson() { var contact_person_list = document.getElementById("contact-person-list"); const contact_person_list_base = document.querySelector( "#contact-person-list-clone tbody tr" ); contact_person_list.appendChild(contact_person_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var contactPersonIdDateNow = uniqId(); var newContactPersonFullnameId = "contact-person-fullname-" + contactPersonIdDateNow; var newContactPersonFirstnameId = "contact-person-firstname-" + contactPersonIdDateNow; var newContactPersonLastnameId = "contact-person-lastname-" + contactPersonIdDateNow; var newContactPersonEmailId = "contact-person-email-" + contactPersonIdDateNow; var newContactPersonMobileId = "contact-person-mobile-" + contactPersonIdDateNow; var item = []; item[0] = newContactPersonFullnameId; item[1] = newContactPersonEmailId; item[2] = newContactPersonMobileId; $("#modal-contact-person-fullname").attr("id", newContactPersonFullnameId); $("#modal-contact-person-email").attr("id", newContactPersonEmailId); $("#modal-contact-person-mobile").attr("id", newContactPersonMobileId); return item; } function addRowInterest() { $("#addRow").click(function () { if ( !checkIfInterestIncomplete() && $("#interest-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the interest/hobbies details first" ); } else { addInterestItem(); } }); $("#interest-list").on("click", ".btnRemove", function () { $(this).closest("tr").remove(); }); } function getAllInterestTableData() { var $table = $("#interest-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfInterestIncomplete() { rows = getAllInterestTableData(); var interestJsonRow = rows; var hasMatch = true; for (var index = 0; index < interestJsonRow.length; ++index) { var interestJson = interestJsonRow[index]; if (interestJson.Category == "" || interestJson.Interest == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function addRowAffiliations() { $("#addRowAffiliations").click(function () { if ( !checkIfAffiliationsIncomplete() && $("#affiliations-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the affiliation details first" ); } else { addAffiliationsItem(); } }); $("#affiliations-list").on("click", ".btnRemoveAffiliations", function () { $(this).closest("tr").remove(); }); } function getAllAffiliationsTableData() { var $table = $("#affiliations-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html().replace(/\s/g, "_").replace(/\./g, "")); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfAffiliationsIncomplete() { rows = getAllAffiliationsTableData(); var jsonRow = rows; var hasMatch = true; for (var index = 0; index < jsonRow.length; ++index) { var json = jsonRow[index]; if (json.Category == "" || json.Affiliations == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function refreshModalReligion() { $.ajax({ url: "api/religion/religion.php", method: "POST", data: { apiKey: "2011315786548487", }, cache: false, beforeSend: function () {}, success: function (result) { var obj = jQuery.parseJSON(result); $("#mod-dd-religion").select2({ tags: true, placeholder: "Select Religion", allowClear: true, data: obj, }); }, }); } function resetCustomerModal() { $("#mod-dd-nationality").val("608").trigger("change"); $("#interest-list-table > tbody").empty(); $("#affiliations-list-table > tbody").empty(); $("#contact-person-list-table > tbody").empty(); $("#children-list-table > tbody").empty(); $("#data-source-list-table > tbody").empty(); $("#educational-bg-list-table > tbody").empty(); $("#car-clubs-list-table > tbody").empty(); $("#unit-association-list-table > tbody").empty(); $("#political-clubs-list-table > tbody").empty(); $("#network-marketing-list-table > tbody").empty(); $("#media-publications-list-table > tbody").empty(); $("#sme-groups-list-table > tbody").empty(); $("#fraternities-sororities-list-table > tbody").empty(); $("#facebook-groups-list-table > tbody").empty(); $("#celebrity-influencers-list-table > tbody").empty(); addCustomerModalTabSelectedTab(1); } function checkFieldsModal(isIndividual) { if (isIndividual) { $(".children-stepper").show(); $(".interest-stepper").show(); $(".interest-list").show(); $("#div-mod-firstname").show(); $("#div-mod-middlename").show(); $("#div-mod-lastname").show(); $("#div-mod-suffix").show(); $("#div-corporation-name").hide(); $("#mod-birthdate-label").text("Date of birth"); $("#div-mod-gender").show(); $("#div-mod-nationality").show(); $("#div-mod-occupation").show(); $("#div-mod-marital-status").show(); // $('#mod-contact-corporation-div').hide(); // $('#mod-contact-div').show(); $("#div-mod-spouse").show(); $("#div-mod-no-of-children").show(); $("#div-mod-business-company").show(); $("#div-mod-position").show(); $("#div-mod-religion").show(); $("#div-mod-profession").show(); $("#div-corporation-name").hide(); $("#div-mod-age-of-company").hide(); $("#educational_bg_div").show(); } else { $(".children-stepper").hide(); $(".interest-stepper").hide(); $(".interest-list").hide(); $("#div-mod-firstname").hide(); $("#div-mod-middlename").hide(); $("#div-mod-lastname").hide(); $("#div-mod-suffix").hide(); $("#div-corporation-name").show(); $("#mod-birthdate-label").text("Date Established"); $("#div-mod-gender").hide(); $("#div-mod-nationality").hide(); $("#div-mod-occupation").hide(); $("#div-mod-marital-status").hide(); // $('#mod-contact-corporation-div').show(); // $('#mod-contact-div').hide(); $("#div-mod-spouse").hide(); $("#div-mod-no-of-children").hide(); $("#div-mod-business-company").hide(); $("#div-mod-position").hide(); $("#div-mod-religion").hide(); $("#div-mod-profession").hide(); $("#div-mod-date-established").show(); $("#div-mod-age-of-company").show(); $("#educational_bg_div").hide(); } } function addCustomerModalTabSelectedTab(type) { $("#customer-modal-tab .nav-link").removeClass("active"); $("#customer-modal-tab-content .tab-pane").removeClass("show"); $("#customer-modal-tab-content .tab-pane").removeClass("active"); switch (type) { case 1: $("#customer-modal-tab-information").addClass("active"); $("#customer-modal-information").addClass("active"); $("#customer-modal-information").addClass("show"); break; case 2: $("#customer-modal-tab-contact").addClass("active"); $("#customer-modal-contact").addClass("active"); $("#customer-modal-contact").addClass("show"); break; case 3: $("#customer-modal-tab-children").addClass("active"); $("#customer-modal-children").addClass("active"); $("#customer-modal-children").addClass("show"); break; case 4: $("#customer-modal-tab-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("show"); break; case 5: $("#customer-modal-tab-interest").addClass("active"); $("#customer-modal-interest").addClass("active"); $("#customer-modal-interest").addClass("show"); break; } } function uniqId() { return Math.round(new Date().getTime() + Math.random() * 100); } function checkIfEmpty(value, row, index) { if (value == "" || value == "-" || value == null) { return "<span style='color:red;'> (Not Provided) </span>"; } return value; } function getCookie(name) { var match = document.cookie.match(RegExp("(?:^|;\\s*)" + name + "=([^;]*)")); return match ? match[1] : null; } function imageFormatter(value, row, index) { return ( '<img width="50px" height="50px" class="user-image img-circle elevation-2" src="dist/img/thumbnail/' + value + '" />' ); } function initToolTip() { var bootstrapTooltip = $.fn.tooltip.noConflict(); $.fn.bstooltip = bootstrapTooltip; $(".tooltip-me").bstooltip(); } function tableMobileFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='tel:" + value + "'>" + value + "</a>"; } function tableNameFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } //ACTIVE LINK TRIGGER EDIT return "<a href='customer_update_view.php?q=" + row.id + "'>" + value + "</a>"; } function tableEmailFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='mailto:" + value + "'>" + value + "</a>"; } function addDataSourceItem() { var data_source = document.getElementById("data-source-list"); const data_source_base = document.querySelector( "#data-source-list-clone tbody tr" ); data_source.appendChild(data_source_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var dataSourceIdDateNow = uniqId(); var newDataSourceCustomerNoId = "data-source-customer-no-" + dataSourceIdDateNow; var newDataSourceDmsId = "data-source-dms-" + dataSourceIdDateNow; var newDataSourceCompanyId = "data-source-company-" + dataSourceIdDateNow; var newDataSourceDealerId = "data-source-dealer-" + dataSourceIdDateNow; var dataSourceItem = []; dataSourceItem[0] = newDataSourceCustomerNoId; dataSourceItem[1] = newDataSourceDmsId; dataSourceItem[2] = newDataSourceCompanyId; dataSourceItem[3] = newDataSourceDealerId; $("#input-modal-customer-no").attr("id", newDataSourceCustomerNoId); $("#" + newDataSourceCustomerNoId) .on("keyup", removeextra) .blur(removeextra); $("#" + newDataSourceCustomerNoId).on("keypress", function (e) { var regex = new RegExp("^[0-9a-zA-Z]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; }); $("#select-modal-dms").attr("id", newDataSourceDmsId).select2({ placeholder: "Select DMS", allowClear: true, }); $("#select-modal-company") .attr("id", newDataSourceCompanyId) .select2({ placeholder: "Select Company", allowClear: true, language: { noResults: function () { return "Select DMS first"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/company/company.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term dms_id: $("#" + newDataSourceDmsId).val(), apiKey: "3568127986733141", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-preferred-moc").select2({ placeholder: "Select mode of contact", allowClear: true, tags: false, minimumResultsForSearch: -1, language: { noResults: function () { return "Select mode of contact"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/mode_of_contact/mode_of_contact.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "1557741601453763", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-business-company").select2({ placeholder: "Search Company by name, email and mobile", allowClear: true, language: { noResults: function () { return "Search Company by name, email and mobile"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/customer/customerv2.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "3975247589935894", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#select-modal-dealer") .attr("id", newDataSourceDealerId) .select2({ placeholder: "Select Dealer", allowClear: true, language: { noResults: function () { return "Search or enter dealer name"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/dealer/dealer.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6209267133015033", company_id: $("#" + newDataSourceCompanyId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newDataSourceDmsId).on("change", function (event) { $("#" + newDataSourceCompanyId) .val("") .trigger("change"); }); $("#" + newDataSourceCompanyId).on("change", function (event) { $("#" + newDataSourceDealerId) .val("") .trigger("change"); }); return dataSourceItem; } function addInterestItem() { // CREATE ROW var interest_list = document.getElementById("interest-list"); const interest_list_base = document.querySelector( "#interest-list-clone tbody tr" ); var interestItem = []; interest_list.appendChild(interest_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var InterestIdDateNow = uniqId(); var newInterestCategoryId = "interest-category-" + InterestIdDateNow; var newInterestContentId = "interest-content-" + InterestIdDateNow; interestItem[0] = newInterestCategoryId; interestItem[1] = newInterestContentId; // alert(interestItem.pop(0)); // alert(interestItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category").attr("id", newInterestCategoryId).select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content") .attr("id", newInterestContentId) .select2({ tags: true, placeholder: "Select", allowClear: true, language: { noResults: function () { return "Search or enter interest"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter interest", ajax: { url: "api/interest_hobbies/interest_hobbies.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "5068581874181452", interestCategory: $("#" + newInterestCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newInterestCategoryId).on("select2:select", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); $("#" + newInterestCategoryId).on("select2:unselecting", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); return interestItem; // CREATE ROW } function addAffiliationsItem() { // CREATE ROW var affiliations_list = document.getElementById("affiliations-list"); const affiliations_list_base = document.querySelector( "#affiliations-list-clone tbody tr" ); var affiliationsItem = []; affiliations_list.appendChild(affiliations_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var affiliationsIdDateNow = uniqId(); var newaffiliationsCategoryId = "affiliations-category-" + affiliationsIdDateNow; var newaffiliationsContentId = "affiliations-content-" + affiliationsIdDateNow; affiliationsItem[0] = newaffiliationsCategoryId; affiliationsItem[1] = newaffiliationsContentId; // alert(affiliationsItem.pop(0)); // alert(affiliationsItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category-affiliations") .attr("id", newaffiliationsCategoryId) .select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content-affiliations") .attr("id", newaffiliationsContentId) .select2({ tags: true, placeholder: "Search or enter affiliations", allowClear: true, language: { noResults: function () { return "Search or enter affiliations"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter affiliations", ajax: { url: "api/affiliations/affiliations.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8048636851659915", affiliationsCategory: $("#" + newaffiliationsCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); // $('#' + newaffiliationsCategoryId).on('select2:select', function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); // $('#' + newaffiliationsCategoryId).on("select2:unselecting", function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); return affiliationsItem; // CREATE ROW } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function () { $("#addRowDataSource").click(function () { if ( !checkIfDataSourceIncomplete() && $("#data-source-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data source details first" ); } else { addDataSourceItem(); } }); $("#data-source-list").on("click", ".btnRemoveDataSource", function () { if ($("#data-source-list-table tbody tr").length < 2) { sweetAlertSimple("error", "Oops...", "Need at least 1 data source"); } else { $(this).closest("tr").remove(); } }); $("#addRowChildren").click(function () { var validate_data_children_list = checkIfChildrenIncomplete(); if ( !validate_data_children_list[0] && $("#children-list-table tbody tr").length > 0 ) { sweetAlertSimple("error", "Oops...", "Complete the child details first"); } else if (!validate_data_children_list[1]) { sweetAlertSimple("error", "Oops...", "Children data invalid mobile"); } else { addCustomerChildren(); } }); $("#children-list").on("click", ".btnRemoveChildren", function () { $(this).closest("tr").remove(); }); $("#addRowContactPerson").click(function () { var validate_data_contact_person = checkIfContactPersonIncomplete(); if ( !validate_data_contact_person[0] && $("#contact-person-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data of contact person first" ); } else if (!validate_data_contact_person[1]) { sweetAlertSimple("error", "Oops...", "Contact person invalid email"); } else if (!validate_data_contact_person[2]) { sweetAlertSimple("error", "Oops...", "Contact person invalid mobile"); } else { addCustomerContactPerson(); } }); $("#contact-person-list").on("click", ".btnRemoveContactPerson", function () { $(this).closest("tr").remove(); }); //Date picker $("#mod-birth-date").datetimepicker({ format: "L", }); $("#mod-established-date").datetimepicker({ format: "L", }); $("[data-mask]").inputmask(); $("#modal-customer").on("hidden.bs.modal", function (e) { $(this) .find("input,textarea") .val("") .end() .find("select") .prop("selectedIndex", 0) .find("input[type=checkbox], input[type=radio]") .prop("checked", "") .end(); $(".modal-select2").val("").trigger("change"); }); $("#modal-customer").on("shown.bs.modal", function () { $("input:text:visible:first").focus(); }); $(document).on("wheel", "input[type=number]", function (e) { $(this).blur(); }); $("#mod-nature-of-business").select2({ // tags: true, placeholder: "Select Nature of Business", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/nature_of_business/nature_of_business.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6902545878701742", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-profession").select2({ tags: true, placeholder: "Select Profession", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/profession/profession.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8920139547181378", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-inquiry").select2({ placeholder: "Select Source of Inquiry", allowClear: true, }); $("#mod-dd-gender").select2({ placeholder: "Select Gender", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-marital-status").select2({ placeholder: "Select Marital Status", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-nationality").select2({ placeholder: "Select Nationality", allowClear: true, }); addRowInterest(); addRowAffiliations(); refreshModalReligion(); refreshModalCities(); initToolTip(); }); PK 8F�ZupV� � dealer_assigned_user_list.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return '';//'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''//'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: '8666264351338448' }, beforeSend: function() {}, success: function(result) { // a=result.total_icu.replace(/\,/g,''); // 1125, but a string, so convert it to number // total_avail_inactive=parseInt(a,10); // $("#no_assign").attr({ // "max" : total_avail_inactive, // "min" : 1 // }); // $('#total_customer_count').text(result.total_icu); // if(result.total_icu ==0) // { // $("#sl_company").attr('disabled', true); // $("#btn-submit-manually").attr('disabled', true); // } // else // { // $("#sl_company").attr('disabled', false); // $("#btn-submit-manually").attr('disabled', false); // } // $('#new_customer_count').text(result.new_customer_count); // $('#updated_customer_count').text(result.updated_customer_count); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { // url: 'app/table/bt_dealer_assignment_update_list.php' url: 'app/table/bt_dealer_assigned_user_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_customer_update_list.php', type: "POST", dataType: 'json', data: { search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var filter_sc = ($("#filter-sc").val() == '') ? '0' : $("#filter-sc").val(); var filter_dealer = ($("#filter-dealer").val() == '') ? '0' : $("#filter-dealer").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { ref_header : ref_header, search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month: filter_month, filter_year: filter_year, filter_sc : filter_sc, filter_dealer : filter_dealer, customer_actions: customer_actions, my_records : my_records }; } // function customerModal(isIndividual) { // new_customer_is_individual = isIndividual; // $('#proceed-button').text("Add Customer"); // $('.customer-modal-overlay').hide(); // if (isIndividual) { // $('#modal-title').text("New Customera (Individual)"); // checkFieldsModal(true); // } else { // $('#modal-title').text("New Customerb (Corporation)"); // checkFieldsModal(false); // } // resetCustomerModal(); // $("#addRowDataSource").click(); // } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); // $('#gender').off('change.mychange').on('change.mychange', function() { // $('#customer-actions').off('change.mychange'); // $('#customer-actions').val('').trigger('change') // addFilterListenerCustomerAction(); // refreshTableCustomer(); // }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-month').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-year').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-sc').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-dealer').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#filter-month').select2({ placeholder: "Month", allowClear: true }) $('#filter-year').select2({ placeholder: "Year", allowClear: true }) $('#filter-sc').select2({ placeholder: "Employee", allowClear: true }) $('#filter-dealer').select2({ placeholder: "Dealer", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter document.getElementById("dropdown-filter").addEventListener('click', function(event) { event.stopPropagation(); }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#filter-month').off('change.mychange'); $('#filter-year').off('change.mychange'); $('#filter-sc').off('change.mychange'); $('#filter-dealer').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#filter-month').val('').trigger('change') $('#filter-year').val('').trigger('change') $('#filter-sc').val('').trigger('change') $('#filter-dealer').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); const goBack = () => { window.history.back(); } $(document).on('click', ".rmv-bt", function() { Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "api/customer_update/assign_dealer_user.php", type: "POST", dataType: 'json', data: { apiKey: skey,val: $(this).val() },success: function(response) { if(response.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: response.msg, allowEnterKey: true // default value }); // location.reload(); setTimeout(()=>{ Swal.close() ; // setTimeout(function () { // Swal.close() // }, 2000) },2000); location.reload(); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: response.msg, allowEnterKey: true // default value }); } } }); } }); }); PK 8F�Z�s L�� �� dealer_user_management.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return '';//'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''//'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/customerv2_update.php", type: "POST", dataType: 'json', data: { dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { a=result.total_icu.replace(/\,/g,''); total_avail_inactive=parseInt(a,10); $("#no_assign").attr({ "max" : total_avail_inactive, "min" : 1 }); $('#total_customer_count').text(result.total_icu); if(result.total_icu ==0) { $("#sl_company").attr('disabled', true); $("#btn-submit").attr('disabled', true); } else { $("#sl_company").attr('disabled', false); $("#btn-submit").attr('disabled', false); } } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_dealer_user_management_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } // customer_grid = $.ajax({ // url: 'app/table/bt_customer_update_list.php', // type: "POST", // dataType: 'json', // data: { // search: search, // grid: 1, // offset: offset, // limit: limit, // dms: dms, // company: company, // type: type, // gender: gender, // filter_age: filter_age, // filter_data: filter_data, // customer_actions: customer_actions, // my_records : my_records // }, // beforeSend: function() { // $('#loader-main').show(); // }, // success: function(result) { // // result.total // $('#customer-grid-data').html(''); // $('#customer-grid-data').append(result.customer_list); // $('#customer-grid-data-paging').html(''); // // if(result.total <= 0){ // // $('#customer-grid-data-paging').append(result.customer_list_paging); // // } // // if(result.grid_offset > 6){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // // } // $('#loader-main').hide(); // } // }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // // alert("click outside"); // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); function dealership() { $.ajax({ url: "api/customer_update/dealer_users_management.php", type: "POST", dataType: 'json', data: { apiKey: 'mRLAZ8te7cnv', }, beforeSend: function() {}, success: function(result) { $.each(result, function(key, value) { $('#sl_dealer') .append($("<option></option>") .attr("value",value.id) .attr("data-id", value.data_scd_id) .text(value.text)); }); } }); } dealership(); $("#sl_dealer").on('change', function(){ // alert($(this).val()) if($(this).val()==="") { $("#btn-submit").attr('disabled',true); } else { $("#btn-submit").attr('disabled',false); } let selectedOption = $(this).find(':selected'); let dataId = selectedOption.data('id'); $.ajax({ url: "api/customer_update/dealer_users_management.php", type: "POST", dataType: 'json', data: { apiKey: 'f5AHTwg8MF9c', did: dataId ,//$(this).val() }, // beforeSend: function() {}, success: function(result) { $("#sl_manager").empty(); $("#sl_manager").prop( "disabled", false ); $('#sl_manager').prepend('<option selected disabled>Select User</option>'); $.each(result, function(key, value) { // alert(value.scd_id); $('#sl_manager') .append($("<option></option>") .attr("value",value.id) .attr("data-id", value.data_id) .text(value.text)); }); } }); }); $("#sl_manager").on('change', function(){ var selectedOption = $(this).find(':selected'); var dataId = selectedOption.data('id'); $.ajax({ url: "api/customer_update/dealer_users_management.php", type: "POST", dataType: 'json', data: { apiKey: 'L9T6kZfc8K4D', scdid : dataId, smid: $(this).val(), }, // beforeSend: function() {}, success: function(result) { $("#sl_user").prop( "disabled", false ); $("#sl_user").empty(); $.each(result, function(key, value) { $('#sl_user') .append($("<option></option>") .attr("value",value.id) .text(value.text)); }); } }); }); function relodMdl() { location.reload(); } $("#btn-submit").on('click', function(e) { let action = $("#action_").val(); e.preventDefault(); Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "api/customer_update/dealer_users_management.php", type: "POST", dataType: 'json', data: { apiKey: apy, did: $("#sl_dealer").val(), smid: $("#sl_manager").val(), sc: $("#sl_user").val(), action : action, id_ : id_ }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text:result.msg , allowEnterKey: true // default value }); setTimeout(()=>{ location.reload(); },1300); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } } }); } }); }); $(document).on('click', ".rmv-bt", function() { Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "api/customer_update/dealer_users_management.php", type: "POST", dataType: 'json', data: { apiKey: spy, id: $(this).val(), }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text:result.msg , allowEnterKey: true // default value }); setTimeout(()=>{ location.reload(); },1300); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } } }); } }); }); $(document).on('click', ".edit-bt", function() { $("#btn-submit") .val('Update') .text("Update") .addClass('btn btn-info') .css({ 'background-color': '#007bff', 'color': 'white', 'border': 'none' }); $("#action_").val('Update'); changeFormTitle(); $("#btn-cancel").show(); $("#btn-submit").attr('disabled',false); let action = $("#action_").val(); var $this = $(this); // Store reference to $(this) id_ =$this.val(); // alert(id_); $("#sl_dealer").val($this.data('dealer')); let selectedOption = $("#sl_dealer").find(':selected'); let dataId = selectedOption.data('id'); $.ajax({ url: "api/customer_update/dealer_users_management.php", type: "POST", dataType: 'json', data: { apiKey: 'f5AHTwg8MF9c', did: dataId, 'action': action, }, success: function(result) { $("#sl_manager").empty(); $("#sl_manager").prop("disabled", false); $.each(result, function(key, value) { $('#sl_manager').append($("<option></option>") .attr("value", value.id) .attr("data-id", value.data_id) .text(value.text)); }); $("#sl_manager").val($this.data('manager')); let selectedOptions = $("#sl_manager").find(':selected'); let dataIdmanager = selectedOptions.data('id'); $.ajax({ url: "api/customer_update/dealer_users_management.php", type: "POST", dataType: 'json', data: { apiKey: 'L9T6kZfc8K4D', scdid : dataIdmanager, smid: $("#sl_manager").val(), }, // beforeSend: function() {}, success: function(result) { $("#sl_user").prop( "disabled", false ); $("#sl_user").empty(); let sc_ =$this.data('sc'); var hasComma = /,/.test(sc_); if(hasComma) { var selectedValues = sc_.split(','); $.each(result, function(key, value) { var option = $("<option></option>") .attr("value", value.id) .text(value.text); // Check if the option value is in the selectedValues list if (selectedValues.includes(value.id.toString())) { option.prop("selected", true); // Set the option as selected } $('#sl_user').append(option); }); } else { var selectedValues = sc_; $.each(result, function(key, value) { var option = $("<option></option>") .attr("value", value.id) .text(value.text); // Check if the option value is in the selectedValues list if (selectedValues== value.id) { option.prop("selected", true); // Set the option as selected } $('#sl_user').append(option); }); } } }); $("#sl_dealer").focus(); } }); }); function changeFormTitle(){ $("#legend_").text($("#action_").val()); } changeFormTitle(); $("#btn-cancel").on('click', function(){ location.reload(); }); $(document).ready(function(){ const goBack = () => { window.history.back(); } }); PK 8F�Z1̶��� �� dealer_cu_user_management.jsnu �[��� var force_update = 0; var force_update_reason = ""; function removeextra() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9a-zA-Z]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function removeextranumonly() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9()-]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function getCustomerAllModalData() { var /* Create an object. */ obj = {}, /* Create a variable that references the current object (default → obj). */ ref = obj; /* Iterate over every input. */ $("#modal-customer :input").each(function () { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute("nodetype") == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute("json-modal") == "true") { ref[id] = $(this).val(); } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function sweetAlertSimple(icon, title, text) { // Swal.fire({ // icon: icon, // title: title, // text: text, // allowEnterKey: true // default value // }) toastr.remove(); switch (icon) { case "success": toastr.success(text); break; case "info": toastr.info(text); break; case "warning": toastr.warning(text); break; case "error": toastr.error(text); break; } } function getAllDataSourceTableData() { var $table = $("#data-source-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { var new_header = $(this).html().replace(/\s/g, "_").replace(/\./g, ""); header.push(new_header); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { if (header[i] == "Customer_No") { var key = header[i], value = $(this).find("input").val(); row[key] = value; } else { var key = header[i], value = $(this).find("select").val(); row[key] = value; } }); rows.push(row); }); return rows; } function checkIfDataSourceIncomplete() { rows = getAllDataSourceTableData(); var dataSourceJsonRow = rows; var hasMatch = true; for (var index = 0; index < dataSourceJsonRow.length; ++index) { var dataSourceJson = dataSourceJsonRow[index]; if ( // dataSourceJson.Customer_No == "" || dataSourceJson.DMS == "" || dataSourceJson.Company == "" || dataSourceJson.Dealer == "" ) { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function handleError(xhr, status, error) { //hide loader sweetAlertSimple("error", "Oops...", "Error has occurred, Try again..."); $("#proceed-button").attr("disabled", false); $(".customer-modal-overlay").hide(); force_update = 0; force_update_reason = ""; } function refreshModalCities() { $.ajax({ url: "api/city/city.php", type: "GET", dataType: "json", data: { apiKey: "5881641680981247", }, beforeSend: function () { $("#mod-dd-city-1").prop("disabled", true); $("#mod-dd-city-2").prop("disabled", true); }, success: function (result) { $("#mod-dd-city-1").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-2").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-1").prop("disabled", false); $("#mod-dd-city-2").prop("disabled", false); }, }); } function checkIfChildrenIncomplete() { rows = getAllChildrenTableData(); var childrenJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; for (var index = 0; index < childrenJsonRow.length; ++index) { var childrenJson = childrenJsonRow[index]; if ( childrenJson.Firstname == "" || childrenJson.Lastname == "" || childrenJson.Birthday == "" ) { hasMatch[0] = false; break; } if (!isEmpty(childrenJson.Mobile)) { if (childrenJson.Mobile.length < 10) { hasMatch[1] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllChildrenTableData() { var $table = $("#children-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function isEmail(email) { var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return regex.test(email); } function isEmpty(string) { var flag = false; try { if (string.trim() == "") { flag = true; } else if (string == null) { flag = true; } else if (typeof string === "undefined") { flag = true; } } catch (err) { // console.log(err); flag = true; } return flag; } function checkIfContactPersonIncomplete() { rows = getAllContactPersonTableData(); var contactPersonJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; hasMatch[2] = true; for (var index = 0; index < contactPersonJsonRow.length; ++index) { var contactPersonJson = contactPersonJsonRow[index]; if ( contactPersonJson.Fullname == "" /* || contactPersonJson.Lastname == "" || contactPersonJson.Mobile == ""*/ ) { hasMatch[0] = false; break; } if (contactPersonJson.Email != "") { if (!isEmail(contactPersonJson.Email)) { hasMatch[1] = false; break; } } if (!isEmpty(contactPersonJson.Mobile)) { if (contactPersonJson.Mobile.length < 10) { hasMatch[2] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllContactPersonTableData() { var $table = $("#contact-person-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function addCustomerChildren() { var children_list = document.getElementById("children-list"); const children_list_base = document.querySelector( "#children-list-clone tbody tr" ); children_list.appendChild(children_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var ChildrenIdDateNow = uniqId(); var newChildrenFirstnameId = "children-firstname-" + ChildrenIdDateNow; var newChildrenLastnameId = "children-lastname-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "div-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "append-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayId = "children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "children-birthday-div-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "children-birthday-append-" + ChildrenIdDateNow; var newChildrenMobileId = "children-mobile-append-" + ChildrenIdDateNow; var item = []; item[0] = newChildrenFirstnameId; item[1] = newChildrenLastnameId; item[2] = newChildrenBirthdayId; item[3] = newChildrenMobileId; $("#mod-children-firstname").attr("id", newChildrenFirstnameId); $("#mod-children-lastname").attr("id", newChildrenLastnameId); $("#mod-children-mobile").attr("id", newChildrenMobileId); $("#mod-children-birthdate") .attr("id", newChildrenBirthdayId) .data("target", "#" + newChildrenBirthdayDivId) .inputmask(); $("#mod-children-birthdate-append") .attr("id", newChildrenBirthdayAppendId) .data("target", "#" + newChildrenBirthdayDivId); $("#mod-children-birthdate-div") .attr("id", newChildrenBirthdayDivId) .datetimepicker({ format: "L", }); return item; } function addCustomerContactPerson() { var contact_person_list = document.getElementById("contact-person-list"); const contact_person_list_base = document.querySelector( "#contact-person-list-clone tbody tr" ); contact_person_list.appendChild(contact_person_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var contactPersonIdDateNow = uniqId(); var newContactPersonFullnameId = "contact-person-fullname-" + contactPersonIdDateNow; var newContactPersonFirstnameId = "contact-person-firstname-" + contactPersonIdDateNow; var newContactPersonLastnameId = "contact-person-lastname-" + contactPersonIdDateNow; var newContactPersonEmailId = "contact-person-email-" + contactPersonIdDateNow; var newContactPersonMobileId = "contact-person-mobile-" + contactPersonIdDateNow; var item = []; item[0] = newContactPersonFullnameId; item[1] = newContactPersonEmailId; item[2] = newContactPersonMobileId; $("#modal-contact-person-fullname").attr("id", newContactPersonFullnameId); $("#modal-contact-person-email").attr("id", newContactPersonEmailId); $("#modal-contact-person-mobile").attr("id", newContactPersonMobileId); return item; } function addRowInterest() { $("#addRow").click(function () { if ( !checkIfInterestIncomplete() && $("#interest-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the interest/hobbies details first" ); } else { addInterestItem(); } }); $("#interest-list").on("click", ".btnRemove", function () { $(this).closest("tr").remove(); }); } function getAllInterestTableData() { var $table = $("#interest-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfInterestIncomplete() { rows = getAllInterestTableData(); var interestJsonRow = rows; var hasMatch = true; for (var index = 0; index < interestJsonRow.length; ++index) { var interestJson = interestJsonRow[index]; if (interestJson.Category == "" || interestJson.Interest == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function addRowAffiliations() { $("#addRowAffiliations").click(function () { if ( !checkIfAffiliationsIncomplete() && $("#affiliations-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the affiliation details first" ); } else { addAffiliationsItem(); } }); $("#affiliations-list").on("click", ".btnRemoveAffiliations", function () { $(this).closest("tr").remove(); }); } function getAllAffiliationsTableData() { var $table = $("#affiliations-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html().replace(/\s/g, "_").replace(/\./g, "")); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfAffiliationsIncomplete() { rows = getAllAffiliationsTableData(); var jsonRow = rows; var hasMatch = true; for (var index = 0; index < jsonRow.length; ++index) { var json = jsonRow[index]; if (json.Category == "" || json.Affiliations == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function refreshModalReligion() { $.ajax({ url: "api/religion/religion.php", method: "POST", data: { apiKey: "2011315786548487", }, cache: false, beforeSend: function () {}, success: function (result) { var obj = jQuery.parseJSON(result); $("#mod-dd-religion").select2({ tags: true, placeholder: "Select Religion", allowClear: true, data: obj, }); }, }); } function resetCustomerModal() { $("#mod-dd-nationality").val("608").trigger("change"); $("#interest-list-table > tbody").empty(); $("#affiliations-list-table > tbody").empty(); $("#contact-person-list-table > tbody").empty(); $("#children-list-table > tbody").empty(); $("#data-source-list-table > tbody").empty(); $("#educational-bg-list-table > tbody").empty(); $("#car-clubs-list-table > tbody").empty(); $("#unit-association-list-table > tbody").empty(); $("#political-clubs-list-table > tbody").empty(); $("#network-marketing-list-table > tbody").empty(); $("#media-publications-list-table > tbody").empty(); $("#sme-groups-list-table > tbody").empty(); $("#fraternities-sororities-list-table > tbody").empty(); $("#facebook-groups-list-table > tbody").empty(); $("#celebrity-influencers-list-table > tbody").empty(); addCustomerModalTabSelectedTab(1); } function checkFieldsModal(isIndividual) { if (isIndividual) { $(".children-stepper").show(); $(".interest-stepper").show(); $(".interest-list").show(); $("#div-mod-firstname").show(); $("#div-mod-middlename").show(); $("#div-mod-lastname").show(); $("#div-mod-suffix").show(); $("#div-corporation-name").hide(); $("#mod-birthdate-label").text("Date of birth"); $("#div-mod-gender").show(); $("#div-mod-nationality").show(); $("#div-mod-occupation").show(); $("#div-mod-marital-status").show(); // $('#mod-contact-corporation-div').hide(); // $('#mod-contact-div').show(); $("#div-mod-spouse").show(); $("#div-mod-no-of-children").show(); $("#div-mod-business-company").show(); $("#div-mod-position").show(); $("#div-mod-religion").show(); $("#div-mod-profession").show(); $("#div-corporation-name").hide(); $("#div-mod-age-of-company").hide(); $("#educational_bg_div").show(); } else { $(".children-stepper").hide(); $(".interest-stepper").hide(); $(".interest-list").hide(); $("#div-mod-firstname").hide(); $("#div-mod-middlename").hide(); $("#div-mod-lastname").hide(); $("#div-mod-suffix").hide(); $("#div-corporation-name").show(); $("#mod-birthdate-label").text("Date Established"); $("#div-mod-gender").hide(); $("#div-mod-nationality").hide(); $("#div-mod-occupation").hide(); $("#div-mod-marital-status").hide(); // $('#mod-contact-corporation-div').show(); // $('#mod-contact-div').hide(); $("#div-mod-spouse").hide(); $("#div-mod-no-of-children").hide(); $("#div-mod-business-company").hide(); $("#div-mod-position").hide(); $("#div-mod-religion").hide(); $("#div-mod-profession").hide(); $("#div-mod-date-established").show(); $("#div-mod-age-of-company").show(); $("#educational_bg_div").hide(); } } function addCustomerModalTabSelectedTab(type) { $("#customer-modal-tab .nav-link").removeClass("active"); $("#customer-modal-tab-content .tab-pane").removeClass("show"); $("#customer-modal-tab-content .tab-pane").removeClass("active"); switch (type) { case 1: $("#customer-modal-tab-information").addClass("active"); $("#customer-modal-information").addClass("active"); $("#customer-modal-information").addClass("show"); break; case 2: $("#customer-modal-tab-contact").addClass("active"); $("#customer-modal-contact").addClass("active"); $("#customer-modal-contact").addClass("show"); break; case 3: $("#customer-modal-tab-children").addClass("active"); $("#customer-modal-children").addClass("active"); $("#customer-modal-children").addClass("show"); break; case 4: $("#customer-modal-tab-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("show"); break; case 5: $("#customer-modal-tab-interest").addClass("active"); $("#customer-modal-interest").addClass("active"); $("#customer-modal-interest").addClass("show"); break; } } function uniqId() { return Math.round(new Date().getTime() + Math.random() * 100); } function checkIfEmpty(value, row, index) { if (value == "" || value == "-" || value == null) { return "<span style='color:red;'> (Not Provided) </span>"; } return value; } function getCookie(name) { var match = document.cookie.match(RegExp("(?:^|;\\s*)" + name + "=([^;]*)")); return match ? match[1] : null; } function imageFormatter(value, row, index) { return ( '<img width="50px" height="50px" class="user-image img-circle elevation-2" src="dist/img/thumbnail/' + value + '" />' ); } function initToolTip() { var bootstrapTooltip = $.fn.tooltip.noConflict(); $.fn.bstooltip = bootstrapTooltip; $(".tooltip-me").bstooltip(); } function tableMobileFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='tel:" + value + "'>" + value + "</a>"; } function tableNameFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } //ACTIVE LINK TRIGGER EDIT return "<a href='dealer-view?q=" + row.ref_num_header + "'>" + value + "</a>"; } function tableEmailFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } // return "<a href='mailto:" + value + "'>" + value + "</a>"; return value; } function addDataSourceItem() { var data_source = document.getElementById("data-source-list"); const data_source_base = document.querySelector( "#data-source-list-clone tbody tr" ); data_source.appendChild(data_source_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var dataSourceIdDateNow = uniqId(); var newDataSourceCustomerNoId = "data-source-customer-no-" + dataSourceIdDateNow; var newDataSourceDmsId = "data-source-dms-" + dataSourceIdDateNow; var newDataSourceCompanyId = "data-source-company-" + dataSourceIdDateNow; var newDataSourceDealerId = "data-source-dealer-" + dataSourceIdDateNow; var dataSourceItem = []; dataSourceItem[0] = newDataSourceCustomerNoId; dataSourceItem[1] = newDataSourceDmsId; dataSourceItem[2] = newDataSourceCompanyId; dataSourceItem[3] = newDataSourceDealerId; $("#input-modal-customer-no").attr("id", newDataSourceCustomerNoId); $("#" + newDataSourceCustomerNoId) .on("keyup", removeextra) .blur(removeextra); $("#" + newDataSourceCustomerNoId).on("keypress", function (e) { var regex = new RegExp("^[0-9a-zA-Z]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; }); $("#select-modal-dms").attr("id", newDataSourceDmsId).select2({ placeholder: "Select DMS", allowClear: true, }); $("#select-modal-company") .attr("id", newDataSourceCompanyId) .select2({ placeholder: "Select Company", allowClear: true, language: { noResults: function () { return "Select DMS first"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/company/company.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term dms_id: $("#" + newDataSourceDmsId).val(), apiKey: "3568127986733141", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-preferred-moc").select2({ placeholder: "Select mode of contact", allowClear: true, tags: false, minimumResultsForSearch: -1, language: { noResults: function () { return "Select mode of contact"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/mode_of_contact/mode_of_contact.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "1557741601453763", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-business-company").select2({ placeholder: "Search Company by name, email and mobile", allowClear: true, language: { noResults: function () { return "Search Company by name, email and mobile"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/customer_update/customerv2_update.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "3975247589935894", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#select-modal-dealer") .attr("id", newDataSourceDealerId) .select2({ placeholder: "Select Dealer", allowClear: true, language: { noResults: function () { return "Search or enter dealer name"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/dealer/dealer.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6209267133015033", company_id: $("#" + newDataSourceCompanyId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newDataSourceDmsId).on("change", function (event) { $("#" + newDataSourceCompanyId) .val("") .trigger("change"); }); $("#" + newDataSourceCompanyId).on("change", function (event) { $("#" + newDataSourceDealerId) .val("") .trigger("change"); }); return dataSourceItem; } function addInterestItem() { // CREATE ROW var interest_list = document.getElementById("interest-list"); const interest_list_base = document.querySelector( "#interest-list-clone tbody tr" ); var interestItem = []; interest_list.appendChild(interest_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var InterestIdDateNow = uniqId(); var newInterestCategoryId = "interest-category-" + InterestIdDateNow; var newInterestContentId = "interest-content-" + InterestIdDateNow; interestItem[0] = newInterestCategoryId; interestItem[1] = newInterestContentId; // alert(interestItem.pop(0)); // alert(interestItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category").attr("id", newInterestCategoryId).select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content") .attr("id", newInterestContentId) .select2({ tags: true, placeholder: "Select", allowClear: true, language: { noResults: function () { return "Search or enter interest"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter interest", ajax: { url: "api/interest_hobbies/interest_hobbies.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "5068581874181452", interestCategory: $("#" + newInterestCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newInterestCategoryId).on("select2:select", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); $("#" + newInterestCategoryId).on("select2:unselecting", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); return interestItem; // CREATE ROW } function addAffiliationsItem() { // CREATE ROW var affiliations_list = document.getElementById("affiliations-list"); const affiliations_list_base = document.querySelector( "#affiliations-list-clone tbody tr" ); var affiliationsItem = []; affiliations_list.appendChild(affiliations_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var affiliationsIdDateNow = uniqId(); var newaffiliationsCategoryId = "affiliations-category-" + affiliationsIdDateNow; var newaffiliationsContentId = "affiliations-content-" + affiliationsIdDateNow; affiliationsItem[0] = newaffiliationsCategoryId; affiliationsItem[1] = newaffiliationsContentId; // alert(affiliationsItem.pop(0)); // alert(affiliationsItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category-affiliations") .attr("id", newaffiliationsCategoryId) .select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content-affiliations") .attr("id", newaffiliationsContentId) .select2({ tags: true, placeholder: "Search or enter affiliations", allowClear: true, language: { noResults: function () { return "Search or enter affiliations"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter affiliations", ajax: { url: "api/affiliations/affiliations.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8048636851659915", affiliationsCategory: $("#" + newaffiliationsCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); // $('#' + newaffiliationsCategoryId).on('select2:select', function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); // $('#' + newaffiliationsCategoryId).on("select2:unselecting", function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); return affiliationsItem; // CREATE ROW } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function () { $("#addRowDataSource").click(function () { if ( !checkIfDataSourceIncomplete() && $("#data-source-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data source details first" ); } else { addDataSourceItem(); } }); $("#data-source-list").on("click", ".btnRemoveDataSource", function () { if ($("#data-source-list-table tbody tr").length < 2) { sweetAlertSimple("error", "Oops...", "Need at least 1 data source"); } else { $(this).closest("tr").remove(); } }); $("#addRowChildren").click(function () { var validate_data_children_list = checkIfChildrenIncomplete(); if ( !validate_data_children_list[0] && $("#children-list-table tbody tr").length > 0 ) { sweetAlertSimple("error", "Oops...", "Complete the child details first"); } else if (!validate_data_children_list[1]) { sweetAlertSimple("error", "Oops...", "Children data invalid mobile"); } else { addCustomerChildren(); } }); $("#children-list").on("click", ".btnRemoveChildren", function () { $(this).closest("tr").remove(); }); $("#addRowContactPerson").click(function () { var validate_data_contact_person = checkIfContactPersonIncomplete(); if ( !validate_data_contact_person[0] && $("#contact-person-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data of contact person first" ); } else if (!validate_data_contact_person[1]) { sweetAlertSimple("error", "Oops...", "Contact person invalid email"); } else if (!validate_data_contact_person[2]) { sweetAlertSimple("error", "Oops...", "Contact person invalid mobile"); } else { addCustomerContactPerson(); } }); $("#contact-person-list").on("click", ".btnRemoveContactPerson", function () { $(this).closest("tr").remove(); }); //Date picker $("#mod-birth-date").datetimepicker({ format: "L", }); $("#mod-established-date").datetimepicker({ format: "L", }); $("[data-mask]").inputmask(); $("#modal-customer").on("hidden.bs.modal", function (e) { $(this) .find("input,textarea") .val("") .end() .find("select") .prop("selectedIndex", 0) .find("input[type=checkbox], input[type=radio]") .prop("checked", "") .end(); $(".modal-select2").val("").trigger("change"); }); $("#modal-customer").on("shown.bs.modal", function () { $("input:text:visible:first").focus(); }); $(document).on("wheel", "input[type=number]", function (e) { $(this).blur(); }); $("#mod-nature-of-business").select2({ // tags: true, placeholder: "Select Nature of Business", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/nature_of_business/nature_of_business.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6902545878701742", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-profession").select2({ tags: true, placeholder: "Select Profession", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/profession/profession.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8920139547181378", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-inquiry").select2({ placeholder: "Select Source of Inquiry", allowClear: true, }); $("#mod-dd-gender").select2({ placeholder: "Select Gender", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-marital-status").select2({ placeholder: "Select Marital Status", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-nationality").select2({ placeholder: "Select Nationality", allowClear: true, }); addRowInterest(); addRowAffiliations(); refreshModalReligion(); refreshModalCities(); initToolTip(); }); PK 8F�Zq�e"�� �� dealer_assigned_user_form.jsnu �[��� var force_update = 0; var force_update_reason = ""; function removeextra() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9a-zA-Z]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function removeextranumonly() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9()-]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function getCustomerAllModalData() { var /* Create an object. */ obj = {}, /* Create a variable that references the current object (default → obj). */ ref = obj; /* Iterate over every input. */ $("#modal-customer :input").each(function () { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute("nodetype") == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute("json-modal") == "true") { ref[id] = $(this).val(); } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function sweetAlertSimple(icon, title, text) { // Swal.fire({ // icon: icon, // title: title, // text: text, // allowEnterKey: true // default value // }) toastr.remove(); switch (icon) { case "success": toastr.success(text); break; case "info": toastr.info(text); break; case "warning": toastr.warning(text); break; case "error": toastr.error(text); break; } } function getAllDataSourceTableData() { var $table = $("#data-source-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { var new_header = $(this).html().replace(/\s/g, "_").replace(/\./g, ""); header.push(new_header); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { if (header[i] == "Customer_No") { var key = header[i], value = $(this).find("input").val(); row[key] = value; } else { var key = header[i], value = $(this).find("select").val(); row[key] = value; } }); rows.push(row); }); return rows; } function checkIfDataSourceIncomplete() { rows = getAllDataSourceTableData(); var dataSourceJsonRow = rows; var hasMatch = true; for (var index = 0; index < dataSourceJsonRow.length; ++index) { var dataSourceJson = dataSourceJsonRow[index]; if ( // dataSourceJson.Customer_No == "" || dataSourceJson.DMS == "" || dataSourceJson.Company == "" || dataSourceJson.Dealer == "" ) { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function handleError(xhr, status, error) { //hide loader sweetAlertSimple("error", "Oops...", "Error has occurred, Try again..."); $("#proceed-button").attr("disabled", false); $(".customer-modal-overlay").hide(); force_update = 0; force_update_reason = ""; } function refreshModalCities() { $.ajax({ url: "api/city/city.php", type: "GET", dataType: "json", data: { apiKey: "5881641680981247", }, beforeSend: function () { $("#mod-dd-city-1").prop("disabled", true); $("#mod-dd-city-2").prop("disabled", true); }, success: function (result) { $("#mod-dd-city-1").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-2").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-1").prop("disabled", false); $("#mod-dd-city-2").prop("disabled", false); }, }); } function checkIfChildrenIncomplete() { rows = getAllChildrenTableData(); var childrenJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; for (var index = 0; index < childrenJsonRow.length; ++index) { var childrenJson = childrenJsonRow[index]; if ( childrenJson.Firstname == "" || childrenJson.Lastname == "" || childrenJson.Birthday == "" ) { hasMatch[0] = false; break; } if (!isEmpty(childrenJson.Mobile)) { if (childrenJson.Mobile.length < 10) { hasMatch[1] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllChildrenTableData() { var $table = $("#children-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function isEmail(email) { var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return regex.test(email); } function isEmpty(string) { var flag = false; try { if (string.trim() == "") { flag = true; } else if (string == null) { flag = true; } else if (typeof string === "undefined") { flag = true; } } catch (err) { // console.log(err); flag = true; } return flag; } function checkIfContactPersonIncomplete() { rows = getAllContactPersonTableData(); var contactPersonJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; hasMatch[2] = true; for (var index = 0; index < contactPersonJsonRow.length; ++index) { var contactPersonJson = contactPersonJsonRow[index]; if ( contactPersonJson.Fullname == "" /* || contactPersonJson.Lastname == "" || contactPersonJson.Mobile == ""*/ ) { hasMatch[0] = false; break; } if (contactPersonJson.Email != "") { if (!isEmail(contactPersonJson.Email)) { hasMatch[1] = false; break; } } if (!isEmpty(contactPersonJson.Mobile)) { if (contactPersonJson.Mobile.length < 10) { hasMatch[2] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllContactPersonTableData() { var $table = $("#contact-person-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function addCustomerChildren() { var children_list = document.getElementById("children-list"); const children_list_base = document.querySelector( "#children-list-clone tbody tr" ); children_list.appendChild(children_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var ChildrenIdDateNow = uniqId(); var newChildrenFirstnameId = "children-firstname-" + ChildrenIdDateNow; var newChildrenLastnameId = "children-lastname-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "div-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "append-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayId = "children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "children-birthday-div-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "children-birthday-append-" + ChildrenIdDateNow; var newChildrenMobileId = "children-mobile-append-" + ChildrenIdDateNow; var item = []; item[0] = newChildrenFirstnameId; item[1] = newChildrenLastnameId; item[2] = newChildrenBirthdayId; item[3] = newChildrenMobileId; $("#mod-children-firstname").attr("id", newChildrenFirstnameId); $("#mod-children-lastname").attr("id", newChildrenLastnameId); $("#mod-children-mobile").attr("id", newChildrenMobileId); $("#mod-children-birthdate") .attr("id", newChildrenBirthdayId) .data("target", "#" + newChildrenBirthdayDivId) .inputmask(); $("#mod-children-birthdate-append") .attr("id", newChildrenBirthdayAppendId) .data("target", "#" + newChildrenBirthdayDivId); $("#mod-children-birthdate-div") .attr("id", newChildrenBirthdayDivId) .datetimepicker({ format: "L", }); return item; } function addCustomerContactPerson() { var contact_person_list = document.getElementById("contact-person-list"); const contact_person_list_base = document.querySelector( "#contact-person-list-clone tbody tr" ); contact_person_list.appendChild(contact_person_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var contactPersonIdDateNow = uniqId(); var newContactPersonFullnameId = "contact-person-fullname-" + contactPersonIdDateNow; var newContactPersonFirstnameId = "contact-person-firstname-" + contactPersonIdDateNow; var newContactPersonLastnameId = "contact-person-lastname-" + contactPersonIdDateNow; var newContactPersonEmailId = "contact-person-email-" + contactPersonIdDateNow; var newContactPersonMobileId = "contact-person-mobile-" + contactPersonIdDateNow; var item = []; item[0] = newContactPersonFullnameId; item[1] = newContactPersonEmailId; item[2] = newContactPersonMobileId; $("#modal-contact-person-fullname").attr("id", newContactPersonFullnameId); $("#modal-contact-person-email").attr("id", newContactPersonEmailId); $("#modal-contact-person-mobile").attr("id", newContactPersonMobileId); return item; } function addRowInterest() { $("#addRow").click(function () { if ( !checkIfInterestIncomplete() && $("#interest-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the interest/hobbies details first" ); } else { addInterestItem(); } }); $("#interest-list").on("click", ".btnRemove", function () { $(this).closest("tr").remove(); }); } function getAllInterestTableData() { var $table = $("#interest-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfInterestIncomplete() { rows = getAllInterestTableData(); var interestJsonRow = rows; var hasMatch = true; for (var index = 0; index < interestJsonRow.length; ++index) { var interestJson = interestJsonRow[index]; if (interestJson.Category == "" || interestJson.Interest == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function addRowAffiliations() { $("#addRowAffiliations").click(function () { if ( !checkIfAffiliationsIncomplete() && $("#affiliations-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the affiliation details first" ); } else { addAffiliationsItem(); } }); $("#affiliations-list").on("click", ".btnRemoveAffiliations", function () { $(this).closest("tr").remove(); }); } function getAllAffiliationsTableData() { var $table = $("#affiliations-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html().replace(/\s/g, "_").replace(/\./g, "")); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfAffiliationsIncomplete() { rows = getAllAffiliationsTableData(); var jsonRow = rows; var hasMatch = true; for (var index = 0; index < jsonRow.length; ++index) { var json = jsonRow[index]; if (json.Category == "" || json.Affiliations == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function refreshModalReligion() { $.ajax({ url: "api/religion/religion.php", method: "POST", data: { apiKey: "2011315786548487", }, cache: false, beforeSend: function () {}, success: function (result) { var obj = jQuery.parseJSON(result); $("#mod-dd-religion").select2({ tags: true, placeholder: "Select Religion", allowClear: true, data: obj, }); }, }); } function resetCustomerModal() { $("#mod-dd-nationality").val("608").trigger("change"); $("#interest-list-table > tbody").empty(); $("#affiliations-list-table > tbody").empty(); $("#contact-person-list-table > tbody").empty(); $("#children-list-table > tbody").empty(); $("#data-source-list-table > tbody").empty(); $("#educational-bg-list-table > tbody").empty(); $("#car-clubs-list-table > tbody").empty(); $("#unit-association-list-table > tbody").empty(); $("#political-clubs-list-table > tbody").empty(); $("#network-marketing-list-table > tbody").empty(); $("#media-publications-list-table > tbody").empty(); $("#sme-groups-list-table > tbody").empty(); $("#fraternities-sororities-list-table > tbody").empty(); $("#facebook-groups-list-table > tbody").empty(); $("#celebrity-influencers-list-table > tbody").empty(); addCustomerModalTabSelectedTab(1); } function checkFieldsModal(isIndividual) { if (isIndividual) { $(".children-stepper").show(); $(".interest-stepper").show(); $(".interest-list").show(); $("#div-mod-firstname").show(); $("#div-mod-middlename").show(); $("#div-mod-lastname").show(); $("#div-mod-suffix").show(); $("#div-corporation-name").hide(); $("#mod-birthdate-label").text("Date of birth"); $("#div-mod-gender").show(); $("#div-mod-nationality").show(); $("#div-mod-occupation").show(); $("#div-mod-marital-status").show(); // $('#mod-contact-corporation-div').hide(); // $('#mod-contact-div').show(); $("#div-mod-spouse").show(); $("#div-mod-no-of-children").show(); $("#div-mod-business-company").show(); $("#div-mod-position").show(); $("#div-mod-religion").show(); $("#div-mod-profession").show(); $("#div-corporation-name").hide(); $("#div-mod-age-of-company").hide(); $("#educational_bg_div").show(); } else { $(".children-stepper").hide(); $(".interest-stepper").hide(); $(".interest-list").hide(); $("#div-mod-firstname").hide(); $("#div-mod-middlename").hide(); $("#div-mod-lastname").hide(); $("#div-mod-suffix").hide(); $("#div-corporation-name").show(); $("#mod-birthdate-label").text("Date Established"); $("#div-mod-gender").hide(); $("#div-mod-nationality").hide(); $("#div-mod-occupation").hide(); $("#div-mod-marital-status").hide(); // $('#mod-contact-corporation-div').show(); // $('#mod-contact-div').hide(); $("#div-mod-spouse").hide(); $("#div-mod-no-of-children").hide(); $("#div-mod-business-company").hide(); $("#div-mod-position").hide(); $("#div-mod-religion").hide(); $("#div-mod-profession").hide(); $("#div-mod-date-established").show(); $("#div-mod-age-of-company").show(); $("#educational_bg_div").hide(); } } function addCustomerModalTabSelectedTab(type) { $("#customer-modal-tab .nav-link").removeClass("active"); $("#customer-modal-tab-content .tab-pane").removeClass("show"); $("#customer-modal-tab-content .tab-pane").removeClass("active"); switch (type) { case 1: $("#customer-modal-tab-information").addClass("active"); $("#customer-modal-information").addClass("active"); $("#customer-modal-information").addClass("show"); break; case 2: $("#customer-modal-tab-contact").addClass("active"); $("#customer-modal-contact").addClass("active"); $("#customer-modal-contact").addClass("show"); break; case 3: $("#customer-modal-tab-children").addClass("active"); $("#customer-modal-children").addClass("active"); $("#customer-modal-children").addClass("show"); break; case 4: $("#customer-modal-tab-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("show"); break; case 5: $("#customer-modal-tab-interest").addClass("active"); $("#customer-modal-interest").addClass("active"); $("#customer-modal-interest").addClass("show"); break; } } function uniqId() { return Math.round(new Date().getTime() + Math.random() * 100); } function checkIfEmpty(value, row, index) { if (value == "" || value == "-" || value == null) { return "<span style='color:red;'> (Not Provided) </span>"; } return value; } function getCookie(name) { var match = document.cookie.match(RegExp("(?:^|;\\s*)" + name + "=([^;]*)")); return match ? match[1] : null; } function imageFormatter(value, row, index) { return ( '<img width="50px" height="50px" class="user-image img-circle elevation-2" src="dist/img/thumbnail/' + value + '" />' ); } function initToolTip() { var bootstrapTooltip = $.fn.tooltip.noConflict(); $.fn.bstooltip = bootstrapTooltip; $(".tooltip-me").bstooltip(); } function tableMobileFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='tel:" + value + "'>" + value + "</a>"; } function tableNameFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } //ACTIVE LINK TRIGGER EDIT return "<a href='dealer-view?q=" + row.user_id + "'>" + value + "</a>"; } function tableEmailFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } // return "<a href='mailto:" + value + "'>" + value + "</a>"; return value; } function addDataSourceItem() { var data_source = document.getElementById("data-source-list"); const data_source_base = document.querySelector( "#data-source-list-clone tbody tr" ); data_source.appendChild(data_source_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var dataSourceIdDateNow = uniqId(); var newDataSourceCustomerNoId = "data-source-customer-no-" + dataSourceIdDateNow; var newDataSourceDmsId = "data-source-dms-" + dataSourceIdDateNow; var newDataSourceCompanyId = "data-source-company-" + dataSourceIdDateNow; var newDataSourceDealerId = "data-source-dealer-" + dataSourceIdDateNow; var dataSourceItem = []; dataSourceItem[0] = newDataSourceCustomerNoId; dataSourceItem[1] = newDataSourceDmsId; dataSourceItem[2] = newDataSourceCompanyId; dataSourceItem[3] = newDataSourceDealerId; $("#input-modal-customer-no").attr("id", newDataSourceCustomerNoId); $("#" + newDataSourceCustomerNoId) .on("keyup", removeextra) .blur(removeextra); $("#" + newDataSourceCustomerNoId).on("keypress", function (e) { var regex = new RegExp("^[0-9a-zA-Z]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; }); $("#select-modal-dms").attr("id", newDataSourceDmsId).select2({ placeholder: "Select DMS", allowClear: true, }); $("#select-modal-company") .attr("id", newDataSourceCompanyId) .select2({ placeholder: "Select Company", allowClear: true, language: { noResults: function () { return "Select DMS first"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/company/company.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term dms_id: $("#" + newDataSourceDmsId).val(), apiKey: "3568127986733141", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-preferred-moc").select2({ placeholder: "Select mode of contact", allowClear: true, tags: false, minimumResultsForSearch: -1, language: { noResults: function () { return "Select mode of contact"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/mode_of_contact/mode_of_contact.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "1557741601453763", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-business-company").select2({ placeholder: "Search Company by name, email and mobile", allowClear: true, language: { noResults: function () { return "Search Company by name, email and mobile"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/customer/customerv2.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "3975247589935894", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#select-modal-dealer") .attr("id", newDataSourceDealerId) .select2({ placeholder: "Select Dealer", allowClear: true, language: { noResults: function () { return "Search or enter dealer name"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/dealer/dealer.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6209267133015033", company_id: $("#" + newDataSourceCompanyId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newDataSourceDmsId).on("change", function (event) { $("#" + newDataSourceCompanyId) .val("") .trigger("change"); }); $("#" + newDataSourceCompanyId).on("change", function (event) { $("#" + newDataSourceDealerId) .val("") .trigger("change"); }); return dataSourceItem; } function addInterestItem() { // CREATE ROW var interest_list = document.getElementById("interest-list"); const interest_list_base = document.querySelector( "#interest-list-clone tbody tr" ); var interestItem = []; interest_list.appendChild(interest_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var InterestIdDateNow = uniqId(); var newInterestCategoryId = "interest-category-" + InterestIdDateNow; var newInterestContentId = "interest-content-" + InterestIdDateNow; interestItem[0] = newInterestCategoryId; interestItem[1] = newInterestContentId; // alert(interestItem.pop(0)); // alert(interestItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category").attr("id", newInterestCategoryId).select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content") .attr("id", newInterestContentId) .select2({ tags: true, placeholder: "Select", allowClear: true, language: { noResults: function () { return "Search or enter interest"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter interest", ajax: { url: "api/interest_hobbies/interest_hobbies.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "5068581874181452", interestCategory: $("#" + newInterestCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newInterestCategoryId).on("select2:select", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); $("#" + newInterestCategoryId).on("select2:unselecting", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); return interestItem; // CREATE ROW } function addAffiliationsItem() { // CREATE ROW var affiliations_list = document.getElementById("affiliations-list"); const affiliations_list_base = document.querySelector( "#affiliations-list-clone tbody tr" ); var affiliationsItem = []; affiliations_list.appendChild(affiliations_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var affiliationsIdDateNow = uniqId(); var newaffiliationsCategoryId = "affiliations-category-" + affiliationsIdDateNow; var newaffiliationsContentId = "affiliations-content-" + affiliationsIdDateNow; affiliationsItem[0] = newaffiliationsCategoryId; affiliationsItem[1] = newaffiliationsContentId; // alert(affiliationsItem.pop(0)); // alert(affiliationsItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category-affiliations") .attr("id", newaffiliationsCategoryId) .select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content-affiliations") .attr("id", newaffiliationsContentId) .select2({ tags: true, placeholder: "Search or enter affiliations", allowClear: true, language: { noResults: function () { return "Search or enter affiliations"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter affiliations", ajax: { url: "api/affiliations/affiliations.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8048636851659915", affiliationsCategory: $("#" + newaffiliationsCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); // $('#' + newaffiliationsCategoryId).on('select2:select', function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); // $('#' + newaffiliationsCategoryId).on("select2:unselecting", function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); return affiliationsItem; // CREATE ROW } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function () { $("#addRowDataSource").click(function () { if ( !checkIfDataSourceIncomplete() && $("#data-source-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data source details first" ); } else { addDataSourceItem(); } }); $("#data-source-list").on("click", ".btnRemoveDataSource", function () { if ($("#data-source-list-table tbody tr").length < 2) { sweetAlertSimple("error", "Oops...", "Need at least 1 data source"); } else { $(this).closest("tr").remove(); } }); $("#addRowChildren").click(function () { var validate_data_children_list = checkIfChildrenIncomplete(); if ( !validate_data_children_list[0] && $("#children-list-table tbody tr").length > 0 ) { sweetAlertSimple("error", "Oops...", "Complete the child details first"); } else if (!validate_data_children_list[1]) { sweetAlertSimple("error", "Oops...", "Children data invalid mobile"); } else { addCustomerChildren(); } }); $("#children-list").on("click", ".btnRemoveChildren", function () { $(this).closest("tr").remove(); }); $("#addRowContactPerson").click(function () { var validate_data_contact_person = checkIfContactPersonIncomplete(); if ( !validate_data_contact_person[0] && $("#contact-person-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data of contact person first" ); } else if (!validate_data_contact_person[1]) { sweetAlertSimple("error", "Oops...", "Contact person invalid email"); } else if (!validate_data_contact_person[2]) { sweetAlertSimple("error", "Oops...", "Contact person invalid mobile"); } else { addCustomerContactPerson(); } }); $("#contact-person-list").on("click", ".btnRemoveContactPerson", function () { $(this).closest("tr").remove(); }); //Date picker $("#mod-birth-date").datetimepicker({ format: "L", }); $("#mod-established-date").datetimepicker({ format: "L", }); $("[data-mask]").inputmask(); $("#modal-customer").on("hidden.bs.modal", function (e) { $(this) .find("input,textarea") .val("") .end() .find("select") .prop("selectedIndex", 0) .find("input[type=checkbox], input[type=radio]") .prop("checked", "") .end(); $(".modal-select2").val("").trigger("change"); }); $("#modal-customer").on("shown.bs.modal", function () { $("input:text:visible:first").focus(); }); $(document).on("wheel", "input[type=number]", function (e) { $(this).blur(); }); $("#mod-nature-of-business").select2({ // tags: true, placeholder: "Select Nature of Business", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/nature_of_business/nature_of_business.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6902545878701742", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-profession").select2({ tags: true, placeholder: "Select Profession", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/profession/profession.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8920139547181378", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-inquiry").select2({ placeholder: "Select Source of Inquiry", allowClear: true, }); $("#mod-dd-gender").select2({ placeholder: "Select Gender", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-marital-status").select2({ placeholder: "Select Marital Status", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-nationality").select2({ placeholder: "Select Nationality", allowClear: true, }); addRowInterest(); addRowAffiliations(); refreshModalReligion(); refreshModalCities(); initToolTip(); }); PK 8F�Zq熅� �� sm_dealer_assign_user.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return '';//'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''//'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: '8666264351338448' }, beforeSend: function() {}, success: function(result) { // a=result.total_icu.replace(/\,/g,''); // 1125, but a string, so convert it to number // total_avail_inactive=parseInt(a,10); // $("#no_assign").attr({ // "max" : total_avail_inactive, // "min" : 1 // }); // $('#total_customer_count').text(result.total_icu); // if(result.total_icu ==0) // { // $("#sl_company").attr('disabled', true); // $("#btn-submit-manually").attr('disabled', true); // } // else // { // $("#sl_company").attr('disabled', false); // $("#btn-submit-manually").attr('disabled', false); // } // $('#new_customer_count').text(result.new_customer_count); // $('#updated_customer_count').text(result.updated_customer_count); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { // url: 'app/table/bt_dealer_assignment_update_list.php' url: 'app/table/bt_sm_dealer_assignment_user_update_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ // url: 'app/table/bt_customer_update_list.php', type: "POST", dataType: 'json', data: { search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_active').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('active').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // // alert("click outside"); // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); function users(){ $("#sl_dealer").empty(); $("#sl_dealer").prop( "disabled", false ); $.ajax({ url: "api/customer_update/assign_dealer_user.php", type: "POST", dataType: 'json', data: {apiKey: apy,cdi:ucdi}, beforeSend: function() {}, success: function(result) { $("#sl_user").attr('required',true); $('#sl_user').append($('<option value=""></option>').text('Select User')); $.each(result, function(key, value) { $('#sl_user') .append($("<option></option>") .attr("value",value.id) .text(value.text)); }); } }); }users(); // function company() { // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: 'mRLAZ8te7cnv', // }, // beforeSend: function() {}, // success: function(result) { // $("#sl_company").val(''); // $.each(result, function(key, value) { // $('#sl_company') // .append($("<option></option>") // .attr("value",value.id) // .text(value.text)); // }); // } // }); // } // company(); // $("#sl_company").on('change', function(){ // $("#sl_dealer").empty(); // if($(this).val()!=''){ // $("#sl_dealer").prop( "disabled", false ); // } // else // { // $("#sl_dealer").prop( "disabled", true ); // } // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: 'f5AHTwg8MF9c', // cid:$(this).val() // }, // beforeSend: function() {}, // success: function(result) { // $.each(result, function(key, value) { // $('#sl_dealer') // .append($("<option></option>") // .attr("value",value.id) // .text(value.text)); // }); $("#sl_dealer").val(''); // } // }); // }); // $("#sl_dealer").on('change', function(){ // $("#sl_user").empty(); // if($(this).val()!=''){ // $("#sl_user").prop( "disabled", false ); // } // else // { // $("#sl_user").prop( "disabled", true ); // } // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: 'L9T6kZfc8K4D', // cdi:$(this).val() // }, // beforeSend: function() {}, // success: function(result) { // $.each(result, function(key, value) { // $('#sl_user') // .append($("<option></option>") // .attr("value",value.id) // .text(value.text)); // }); // $("#sl_user").val(''); // } // }); // }); // $("#sl_dealer").on('change', function(){ // $("#no_assign").val(''); // if($(this).val()!=''){ // $("#no_assign").prop( "disabled", false ); // } // else // { // $("#no_assign").prop( "disabled", true ); // } // }); // function autoAssign(apy) // { // $("#spinner-loader").show(); // $('.fieldset').prop('disabled', true) // $(":button").prop('disabled',true); // $("#assign_to_dealers").hide(); // $("#spinner-loader").show(); // $.ajax({ // url: "api/customer_update/assign_dealer.php",//"api/customer_update/customerv2_update.php", // type: "POST", // dataType: 'json', // data: { // apiKey: apy, // // cdi:$(this).val() // }, // // beforeSend: function() {}, // // beforeSend: function(xhr) { // // // Show loader before the request starts // // $("#spinner-loader").show(); // // $('.fieldset').prop('disabled', true); // // $(":button").prop('disabled', true); // // $("#assign_to_dealers").hide(); // // // Track progress // // // Check if xhr.upload is defined before adding the event listener // // if (xhr.upload) { // // xhr.upload.addEventListener("progress", function(evt) { // // if (evt.lengthComputable) { // // var percentComplete = (evt.loaded / evt.total) * 100; // // console.log(percentComplete + "%"); // // // Update the progress bar or display the percentage as needed // // } // // }, false); // // } // // }, // complete: function(){ // $("#spinner-loader").hide(); // $('.fieldset').prop('disabled', false) // $(":button").prop('disabled',false); // $("#assign_to_dealers").show(); // }, // success: function(result) { // if(result.status==0){ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // if(result.status==1){ // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.no_assign+' '+result.msg+' '+result.no_of_dealers+' '+result.dealer, // allowEnterKey: true // default value // }); // location.reload(); // } // } // }); // } // function resetAssign(apy) // { // Swal.fire({ // title: 'Are you sure?', // text: "You are about to execute this command. Do you want to proceed?", // icon: 'warning', // showCancelButton: true, // confirmButtonColor: '#3085d6', // cancelButtonColor: '#d33', // confirmButtonText: 'Yes, execute it!' // }).then((result) => { // if (result.isConfirmed) { // $("#spinner-loader").show(); // $('.fieldset').prop('disabled', true) // $(":button").prop('disabled',true); // $("#reset-assignment").hide(); // $("#spinner-loader-purple").show(); // $.ajax({ // url: "api/customer_update/assign_dealer.php",//"api/customer_update/customerv2_update.php", // type: "POST", // dataType: 'json', // data: { // apiKey: apy, // // cdi:$(this).val() // }, // // beforeSend: function() {}, // // beforeSend: function(xhr) { // // }, // complete: function(){ // $("#spinner-loader-purple").hide(); // $('.fieldset').prop('disabled', false) // $(":button").prop('disabled',false); // $("#reset-assignment").show(); // }, // success: function(result) { // if(result.status==0){ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // if(result.status==1){ // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.no_assign+' '+result.msg+' '+result.no_of_dealers+' '+result.dealer, // allowEnterKey: true // default value // }); // location.reload(); // } // } // }); // } // }); // } // $(document).on('change', '.usr-id', function() { // let hdr = $(this).closest('tr').find('.hdr').val(); // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: $("#ausr-py").val(), // uid:$(this).val(), // hdr:hdr, // }, // success: function(result) { // if(result.status==1) // { // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.msg, // allowEnterKey: true // default value // }); // setTimeout(()=>{ // // location.reload(); // },3000); // }else{ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // } // }); // }); // function relodMdl() // { // location.reload(); // } // function loadDealers(apy){ // $.ajax({ // url: 'api/customer_update/assign_dealer.php', // method: 'POST', // data: {apiKey:apy }, // success: function(response) { // $('#table_dlr tbody').empty(); // // Parse JSON response // var dealers = JSON.parse(response); // // Loop through each dealer object and append to the table // $.each(dealers, function(index, dealer) { // var row = $("<tr>"); // row.append($("<td>").text(index+1)); // row.append($("<td>").text(dealer.text)); // row.append($("<td>").html("<input type='checkbox' class='chk-active-dlr' "+dealer.check+" value='" + dealer.id + "'/>")); // $('#table_dlr tbody').append(row); // }); // $('#table_dlr').DataTable({ // // "scrollY": "300px", // Set fixed height with scrolling // // "lengthMenu": false,//remove select result // "paging": true, // Enable pagination // "searching": true, // Enable search bar // "pagingType": "simple_numbers", // Use buttons for pagination // "language": { // "paginate": { // "previous": "<", // "next": ">" // } // } // }); // }, // error: function(xhr, status, error) { // console.error(error); // Log any errors // } // }); // } // $("#btn-submit-manually").on('click', function(e) { // e.preventDefault(); // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: $("#apiy").val(), // cm: $("#sl_company").val(), // dlr: $("#sl_dealer").val(), // usr: $("#sl_user").val(), // nos: $("#no_assign").val() // }, // success: function(result) { // if(result.status==1) // { // setTimeout(()=>{ // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.nos+' '+result.msg+' '+result.dealer, // allowEnterKey: true // default value // }); // location.reload(); // },3000); // }else{ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // } // }); // }); $(document).ready(function(){ function count_avl_cu() { $("#sl_source").attr('disabled',false); $("#sl_user").attr('disabled',false); $("#btn-submit-manually").attr('disabled',false); $.ajax({ url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: '8666264351338448' }, beforeSend: function() {}, success: function(result) { if(result.total_icu_assigned<=0) { $("#sl_source").attr('disabled',true); $("#sl_user").attr('disabled',true); $("#btn-submit-manually").attr('disabled',true); } else{ $('#total_customer_count').text("/"+ result.total_icu_assigned); a=result.total_icu_assigned.replace(/\,/g,''); total_avail_inactive=parseInt(a,10); if(total_avail_inactive ==0) { $("#no_assign").attr('disabled', true); $("#btn-submit-manually").attr('disabled', true); } else { $("#no_assign").attr({ "max" : total_avail_inactive, "min" : 1 }); $("#sl_user").attr('disabled',false); // $("#no_assign").attr('disabled', false); // $("#btn-submit-manually").attr('disabled', false); } } } }); } count_avl_cu(); function source() { $.ajax({ url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: spy }, beforeSend: function() {}, success: function(result) { $.each(result, function(key, value) { $('#sl_source') .append($("<option></option>") .attr("value",value.id) .text(value.text)); }); } }); } source(); $("#sl_source").on('change', function(){ $("#no_assign").attr('disabled', true); $("#btn-submit-manually").attr('disabled', true); $("#sl_user").attr('disabled', true); $.ajax({ url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: stpy, hdr:$(this).val() }, beforeSend: function() {}, success: function(result) { // a=result.total_avl_customer.replace(/\,/g,''); // total_available_customer=parseInt(a,10); if(parseInt(result.total_avl_customer)>0) { $("#no_assign").attr('disabled', false); $("#btn-submit-manually").attr('disabled', false); $("#sl_user").attr('disabled', false); } } }); }); $("#btn-submit-manually").on('click', function(e) { $("#btn-submit-manually").attr('disabled', true); e.preventDefault(); let shouldSubmit = true; Swal.fire({ title: 'Are you sure?', text: "You are about to assign a customer list to this user. Please ensure that the selected user is under your supervision or within your group under the same dealer to avoid conflicts arising from incorrect assignments.", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { // Check if the select box has a selected option if ($("#sl_user option:selected").val() === "") { Swal.fire({ icon: 'warning', title: 'Oops!', text: "User field is required.", allowEnterKey: true // default value }); $("#sl_user").focus(); $("#btn-submit-manually").attr('disabled', false); shouldSubmit = false; return false; } // If shouldSubmit is true, proceed with AJAX call if (shouldSubmit) { $.ajax({ url: "api/customer_update/assign_dealer_user.php", type: "POST", dataType: 'json', data: { apiKey: xtpy, hdr: $("#sl_source").val(), nos: $("#no_assign").val(), uid: $("#sl_user").val(), }, beforeSend: function() {}, success: function(response) { if(response.status == 1) { Swal.fire({ icon: 'success', title: 'Success!', text: response.msg, allowEnterKey: true // default value }); $("#btn-submit-manually").attr('disabled', false); setTimeout(() => { Swal.close(); location.reload(); }, 2500); } else { Swal.fire({ icon: 'warning', title: 'Oops!', text: response.msg, allowEnterKey: true // default value }); } } }); } } }); }); // $("#btn-submit-manually").on('click', function(e) { // e.preventDefault(); // let shouldSubmit = true; // Swal.fire({ // title: 'Are you sure?', // text: "You are about to assign a customer list to this user. Please ensure that the selected user is under your supervision or within your group under the same dealer to avoid conflicts arising from incorrect assignments.", // icon: 'warning', // showCancelButton: true, // confirmButtonColor: '#3085d6', // cancelButtonColor: '#d33', // confirmButtonText: 'Yes, execute it!' // }).then((result) => { // if (result.isConfirmed) { // if($("#sl_user").val() === "") // { // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: "User field is required.", // allowEnterKey: true // default value // }); // // users(); // // location.reload(); // $("#sl_user").focus(); // shouldSubmit = false; // return false; // } // $.ajax({ // url: "api/customer_update/assign_dealer_user.php", //dealer_customerv2_update.php", // type: "POST", // dataType: 'json', // data: { // apiKey: xtpy, // hdr: $("#sl_source").val(), // nos: $("#no_assign").val(), // uid: $("#sl_user").val(), // }, // beforeSend: function() {}, // success: function(response) { // if(response.status==1) // { // Swal.fire({ // icon: 'success', // title: 'Success!', // text: response.msg, // allowEnterKey: true // default value // }); // setTimeout(()=>{ // Swal.close() ; // location.reload(); // },2500); // }else{ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: response.msg, // allowEnterKey: true // default value // }); // } // } // }); // } // }); // }); }); const goBack = () => { window.history.back(); } PK 8F�Z�qj�� � dealer_assign05-23-24.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return '';//'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''//'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { // console.log('result total' +result); a=result.total_icu.replace(/\,/g,''); // 1125, but a string, so convert it to number total_avail_inactive=parseInt(a,10); $("#no_assign").attr({ "max" : total_avail_inactive, "min" : 1 }); $('#total_customer_count').text(result.total_icu); if(result.total_icu ==0) { $("#sl_company").attr('disabled', true); $("#btn-submit-manually").attr('disabled', true); } else { $("#sl_company").attr('disabled', false); $("#btn-submit-manually").attr('disabled', false); } // $('#new_customer_count').text(result.new_customer_count); // $('#updated_customer_count').text(result.updated_customer_count); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_dealer_assignment_update_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_customer_update_list.php', type: "POST", dataType: 'json', data: { search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ // placeholder: "DMS Type", placeholder: "Batch No", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // // alert("click outside"); // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); function company() { $.ajax({ url: "api/customer_update/assign_dealer.php", type: "POST", dataType: 'json', data: { apiKey: 'mRLAZ8te7cnv', }, beforeSend: function() {}, success: function(result) { $("#sl_company").val(''); $.each(result, function(key, value) { $('#sl_company') .append($("<option></option>") .attr("value",value.id) .text(value.text)); }); } }); } company(); $("#sl_company").on('change', function(){ $("#sl_dealer").empty(); if($(this).val()!=''){ $("#sl_dealer").prop( "disabled", false ); $("#batchNo").prop("disabled",false); } else { $("#sl_dealer").prop( "disabled", true ); } $.ajax({ url: "api/customer_update/assign_dealer.php", type: "POST", dataType: 'json', data: { apiKey: 'f5AHTwg8MF9c', cid:$(this).val() }, beforeSend: function() {}, success: function(result) { $.each(result, function(key, value) { $('#sl_dealer') .append($("<option></option>") .attr("value",value.id) .text(value.text)); }); $("#sl_dealer").val(''); } }); }); // $("#sl_dealer").on('change', function(){ // $("#sl_user").empty(); // if($(this).val()!=''){ // $("#sl_user").prop( "disabled", false ); // } // else // { // $("#sl_user").prop( "disabled", true ); // } // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: 'L9T6kZfc8K4D', // cdi:$(this).val() // }, // beforeSend: function() {}, // success: function(result) { // $.each(result, function(key, value) { // $('#sl_user') // .append($("<option></option>") // .attr("value",value.id) // .text(value.text)); // }); // $("#sl_user").val(''); // } // }); // }); $("#sl_dealer").on('change', function(){ $("#no_assign").val(''); if($(this).val()!=''){ $("#no_assign").prop( "disabled", false ); } else { $("#no_assign").prop( "disabled", true ); } }); function autoAssign(apy) { $("#spinner-loader").show(); $('.fieldset').prop('disabled', true) $(":button").prop('disabled',true); $("#assign_to_dealers").hide(); $("#spinner-loader").show(); $.ajax({ url: "api/customer_update/assign_dealer.php",//"api/customer_update/customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: apy, // cdi:$(this).val() }, // beforeSend: function() {}, // beforeSend: function(xhr) { // // Show loader before the request starts // $("#spinner-loader").show(); // $('.fieldset').prop('disabled', true); // $(":button").prop('disabled', true); // $("#assign_to_dealers").hide(); // // Track progress // // Check if xhr.upload is defined before adding the event listener // if (xhr.upload) { // xhr.upload.addEventListener("progress", function(evt) { // if (evt.lengthComputable) { // var percentComplete = (evt.loaded / evt.total) * 100; // console.log(percentComplete + "%"); // // Update the progress bar or display the percentage as needed // } // }, false); // } // }, complete: function(){ $("#spinner-loader").hide(); $('.fieldset').prop('disabled', false) $(":button").prop('disabled',false); $("#assign_to_dealers").show(); }, success: function(result) { if(result.status==0){ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } if(result.status==1){ Swal.fire({ icon: 'success', title: 'Success!', text: result.no_assign+' '+result.msg+' '+result.no_of_dealers+' '+result.dealer, allowEnterKey: true // default value }); location.reload(); } } }); } function resetAssign(apy) { Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { $("#spinner-loader").show(); $('.fieldset').prop('disabled', true) $(":button").prop('disabled',true); $("#reset-assignment").hide(); $("#spinner-loader-purple").show(); $.ajax({ url: "api/customer_update/assign_dealer.php",//"api/customer_update/customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: apy, // cdi:$(this).val() }, // beforeSend: function() {}, // beforeSend: function(xhr) { // }, complete: function(){ $("#spinner-loader-purple").hide(); $('.fieldset').prop('disabled', false) $(":button").prop('disabled',false); $("#reset-assignment").show(); }, success: function(result) { if(result.status==0){ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } if(result.status==1){ Swal.fire({ icon: 'success', title: 'Success!', text: result.no_assign+' '+result.msg+' '+result.no_of_dealers+' '+result.dealer, allowEnterKey: true // default value }); location.reload(); } } }); } }); } // $(document).on('change', '.usr-id', function() { // let hdr = $(this).closest('tr').find('.hdr').val(); // let did = $(this).closest('tr').find('.did').val(); // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: $("#ausr-py").val(), // uid:$(this).val(), // hdr:hdr, // did:did, // }, // success: function(result) { // if(result.status==1) // { // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.msg, // allowEnterKey: true // default value // }); // setTimeout(()=>{ // // location.reload(); // },3000); // } // if(result.status==0){ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // } // }); // }); function relodMdl() { location.reload(); } function loadDealers(apy){ $.ajax({ url: 'api/customer_update/assign_dealer.php', method: 'POST', data: {apiKey:apy }, success: function(response) { $('#table_dlr tbody').empty(); // Parse JSON response var dealers = JSON.parse(response); // Loop through each dealer object and append to the table $.each(dealers, function(index, dealer) { console.log(dealer); var row = $("<tr>"); row.append($("<td>").text(index+1)); row.append($("<td>").text(dealer.text)); row.append($("<td>").html("<input type='checkbox' class='chk-active-dlr' "+dealer.check+" value='" + dealer.id + "'/>")); row.append($("<td>").html("")); $('#table_dlr tbody').append(row); }); $('#table_dlr').DataTable({ // "scrollY": "300px", // Set fixed height with scrolling // "lengthMenu": false,//remove select result "paging": true, // Enable pagination "searching": true, // Enable search bar "pagingType": "simple_numbers", // Use buttons for pagination "language": { "paginate": { "previous": "<", "next": ">" } } }); }, error: function(xhr, status, error) { console.error(error); // Log any errors } }); } $("#btn-submit-manually").on('click', function(e) { $(this).prop('disabled',true); e.preventDefault(); $.ajax({ url: "api/customer_update/assign_dealer.php", type: "POST", dataType: 'json', data: { apiKey: $("#apiy").val(), btno:$("#batchNo").val(), cm: $("#sl_company").val(), dlr: $("#sl_dealer").val(), usr: $("#sl_user").val(), nos: $("#no_assign").val() }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: result.nos+' '+result.msg+' '+result.dealer, allowEnterKey: true // default value }); setTimeout(()=>{ location.reload(); },1300); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } $("#btn-submit-manually").prop('disabled',false); } }); }); $('#table_dlr').on('click', '.chk-active-dlr', function() { let dlr_id=[]; let active =($(this).is(':checked') ? 1 : 0); let data ={'did':$(this).val(),'active':active}; dlr_id.push(data); }); function chkAll() { let active = ($("#chk_all").is(':checked')) ? 0 : 1; // Determine active status dlr_id = []; // Clear the array // Iterate over all pages of DataTables $('#table_dlr').DataTable().rows().every(function(rowIdx, tableLoop, rowLoop) { // Get the data for each row let data = rowIdx;//this.data(); // Find the checkbox within the row let checkbox = $(this.node()).find('.chk-active-dlr'); // Set the checked state for each checkbox checkbox.prop('checked', active); // Push each checkbox's data into the dlr_id array dlr_id.push({'did': data, 'active': active}); }); console.log(dlr_id); } function exl_dlr() { let dlr_id= []; let active =1; $('#table_dlr').DataTable().rows().every(function(rowIdx, tableLoop, rowLoop) { // Get the data for each row (assuming you need this) let rowData = this.data(); // Find the checkbox within the row let checkbox = $(this.node()).find('.chk-active-dlr'); // Get the value of the checkbox let value = checkbox.val(); // Check if the checkbox is checked let active = (checkbox.is(':checked')) ? 0 : 1; // Push each checkbox's data into the dlr_id array dlr_id.push({'did': value, 'active': active}); }); $.ajax({ url: "api/customer_update/assign_dealer.php", type: 'POST', dataType: 'json', // data: {apiKey:excl_py,attr:active,did:$(this).val()}, data: {apiKey:excl_py,attr:dlr_id}, success: function(response) { if(response.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: response.msg, allowEnterKey: true // default value }); setTimeout(()=>{ Swal.close() ; // setTimeout(function () { // Swal.close() // }, 2000) },3000); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: response.msg, allowEnterKey: true // default value }); } }, error: function(error) { console.error(error); // Log any errors } }); } // } $("#assign_to_dealers").hide(); $("#fieldset-assign").hide(); function swichAssignment() { $('#toggleForms').change(function() { var label = $(this).prop('checked') ? 'Auto' : 'Manual'; $(this).siblings('.custom-control-label').text(label + ''); $(this).siblings('.fieldset-form').text(label + ''); if(label ==='Auto') { $("#assign_to_dealers").show(); $("#fieldset-assign").hide(); } if(label ==='Manual') { $("#assign_to_dealers").hide(); $("#fieldset-assign").show(); } }); } $(document).ready(function(){ $(document).on('click', '.btn-dealer-users', function() { // var didUsersValue = $(this).siblings('.modal-content').find('.did_users').val(); let dealer_id = $(this).attr("data-id"); let dealer_hdr = $(this).attr("data-hdr"); console.log(dealer_id+' '+dealer_hdr); $.ajax({ url: "api/customer_update/assign_dealer.php", type: 'POST', dataType: 'json', // data: {apiKey:excl_py,attr:active,did:$(this).val()}, data: {apiKey:apy,hdr: dealer_hdr,dealer_id : dealer_id}, success: function(response) { var isChecked =''; const userID=[]; const userNoDB=[]; $.each(response.users_in_cu_assigned,function(i,user_id){ userID.push(user_id); userNoDB.push(user_id['total_assigned']); }); console.log(userID); delete response.users_in_cu_assigned; delete response.user_total_assigned_db; $('.modal-body-user').empty(); $('.div-user').empty(); $(this).closest('.modal').find(".dealer_hdrs").empty(); $(this).closest('.modal').find(".daeler_ids").empty(); $(this).closest('.modal-body-user').html(''); // if($.isEmptyObject(response)){ // alert('empty'); // } // console.log(userNoDB); // console.log(userID);return; if(!$.isEmptyObject(response)){ $(".btn-save-users").prop('disabled',false); var divRowDealerInfo = $('<div></div>').addClass('row div-label').css('padding-top','1rem').css('padding-bottom','1rem').css('margin-bottom','10px'); var divRowLable = $('<div></div>').addClass('row div-label').css('padding-top','1rem').css('padding-bottom','1rem').css('margin-bottom','10px'); var actionLabel = $('<div></div>').addClass('col-md-1 ').text('Action').css('font-weight','Bold').css('font-size','15px'); var no_of_db_label = $('<div></div>').addClass('col-md-2 nodColumn').text('No of Database').css('font-weight','Bold').css('font-size','15px'); var gmsm_label= $('<div></div>').addClass('col-md-9').text("GM/SM").css('font-weight','Bold').css('font-size','15px').css('padding-left','1rem'); divRowLable.append(actionLabel,no_of_db_label,gmsm_label); $('.modal-body-user').append(divRowLable); $.each(response, function(e, v) { let currentAssignedDB = ''; let isChecked = false; // Initialize isChecked to false outside the loop // Check each element in userID for matching employee_id for (let i = 0; i < userID.length; i++) { if (userID[i] && typeof userID[i] === 'object' && userID[i]['user_id'].includes(`${v.employee_id}`)) { isChecked = true; currentAssignedDB = userID[i]['total_assigned']; console.log('true ' + userID[i]['user_id'] + ' ' + currentAssignedDB); break; // Exit the inner loop after finding a match } } // Create DOM elements based on the isChecked value var divRow = $('<div></div>').addClass('row div-user'); var checkColumn = $('<div></div>').addClass('col-md-1 '); var nodColumn = $('<div></div>').addClass('col-md-2 nodColumn'); var labelColumn = $('<div></div>').addClass('col-md-9'); var label = $('<label></label>').addClass('lbl-forms form-control').attr('for', 'employee').text(v.employee_name +' - '+v.position); if (isChecked) { var inputCheck = $('<input>').addClass('userID').attr({ 'name': 'userID[]', 'id': 'userID', 'type': 'checkbox','disabled':'disabled'}).val(v.employee_id).prop('checked', isChecked); var inputNoOfDb = $('<span>').attr({'name':'dealer_no_db','placeholder':'Enter no of DB','id':'dealer_no_db','class':'badge'}).text(currentAssignedDB).css('width','110px').css('background-color','#f9ce69').css('margin-top','10px'); } else { var inputCheck = $('<input>').addClass('userID').attr({ 'name': 'userID[]', 'id': 'userID', 'type': 'checkbox','disabled':'disabled'}).val(v.employee_id).prop('checked', isChecked).css('opacity','0.2'); var inputNoOfDb = $('<input>').attr({'name':'dealer_no_db','placeholder':'Enter no of DB','id':'dealer_no_db','required':'required','class':'form-control dealer_no_db','type':'number'}).val(currentAssignedDB).css('width','110px'); } let inputHdr = $('<input>').attr({'name':'dealer_hrd','id':'dealer_hrd','class':'form-control-sm dealer_hdrs','type':'hidden'}).val(dealer_hdr); let inputDid = $('<input>').attr({'name':'dealer_id','id':'dealer_id','class':'form-control-sm dealer_ids','type':'hidden'}).val(dealer_id); inputCheck.css('margin-top', '13px'); // Adjust this value to center the checkbox vertically label.css('margin-left', '-10px'); // Move the label element to the left by 10 pixels label.css('font-size', '16px'); label.css('border', 'none'); label.css('font-style','Italic'); nodColumn.append(inputNoOfDb); checkColumn.append(inputCheck); labelColumn.append(label); divRow.append(checkColumn,nodColumn, labelColumn); $('.modal-body-user').append(divRow,inputHdr,inputDid); }); } else { $(".btn-save-users").prop('disabled',true); $('#UserModal').modal('hide'); var SpanWarning = $('<span></span>').addClass('col-md-12 badge badge-warning').text("No users are available in this dealer."); $('.modal-body-user').append(SpanWarning); // Swal.fire({ // icon: 'warning', // title: 'Warning!', // text: "There is no avilable user to assign", // // allowEnterKey: true // default value // }); } }, error: function(error) { console.error(error); // Log any errors } }); }); // let uidarr = []; // $(document).on('click', '.userID', function() { // let currnetValue = $(this).val(); // if($(this).is(":checked")){ // uidarr= uidarr.concat(currnetValue); // $(this).closest('.modal').find('.nodColumn').show(); // $(this).closest('.modal').find('.nodColumn').focus(); // $(this).closest('.modal').find('.dealer_no_db').attr('required', true); // } // else // { // uidarr = uidarr.filter(element => element !== currnetValue); // $(this).closest('.modal').find('.nodColumn').hide(); // $(this).closest('.modal').find('.dealer_no_db').attr('required', false); // } // var hdrValue = $(this).closest('.modal').find('.dealer_hdrs').val(); // var didUsersValue = $(this).closest('.modal').find('.dealer_ids').val(); // //SALES MANAGER // $('.btn-save-users').off('click').on('click', function() { // var didUsersNoDB = $(this).closest('.modal').find('.dealer_no_db').val(); // if(isNaN(didUsersNoDB) || didUsersNoDB.trim() === ''){ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: 'No of DB field is required', // allowEnterKey: true // default value // }); // } // else{ // var didUsersNoDB = $(this).closest('.modal').find('.dealer_no_db').val(); // Swal.fire({ // title: 'Are you sure?', // text: "You are about to execute this command. Do you want to proceed?", // icon: 'warning', // showCancelButton: true, // confirmButtonColor: '#3085d6', // cancelButtonColor: '#d33', // confirmButtonText: 'Yes, execute it!' // }).then((result) => { // if (result.isConfirmed) { // assignUsers([hdrValue, didUsersValue, uidarr, didUsersNoDB]); // } // }); // } // }); // }); $(document).on('keyup', '.dealer_no_db', function() { let currentCHK = $(this).closest('.div-user').find('.userID'); if ($(this).val() > 0) { currentCHK.prop('disabled', false); currentCHK.css({ 'opacity': '100', 'border': '2px solid black' }); currentCHK.prop('checked', false); // Uncheck the nearby checkbox } else { currentCHK.prop('disabled', true); currentCHK.prop('checked', false); // Uncheck the nearby checkbox currentCHK.css('opacity', '0.2'); } }); let userData = []; // Define userData array to store user data $(document).on('click', '.userID', function() { userData = []; let container = $(this).closest('.modal-body-user'); let currnetValue = $(this).val(); let no_of_db = 0; // Default value let hdr_value = container.find('.dealer_hdrs').val(); let dealer_value = container.find('.dealer_ids').val(); if ($(this).is(":checked")) { // Find the no_of_db input relative to the checkbox that was checked no_of_db = $(this).closest('.div-user').find('.dealer_no_db').val(); // Add user data to userData array if checkbox is checked and no_of_db is filled userData.push([currnetValue, no_of_db, hdr_value, dealer_value]); // $(this).closest('.div-user').find('.nodColumn').show(); $(this).closest('.div-user').find('.dealer_no_db').attr('required', true); } else { // Remove user data from userData array if checkbox is unchecked userData = userData.filter(user => user[0] !== currnetValue); // $(this).closest('.div-user').find('.nodColumn').hide(); $(this).closest('.div-user').find('.dealer_no_db').attr('required', false); } // console.log(userData); }); $(document).on('click', '.btn-save-users', function() { if(userData.length ===0) { Swal.fire({ icon: 'warning', title: 'Oops!', text: 'Please tick the box if you want to assign a user.', allowEnterKey: true // default value }); return; } let noDBEmpty = false; $.each(userData, function(e, v) { // console.log(v[1]) if(isNaN(v[1]) || v[1].trim() == '') { noDBEmpty = true; // Set flag to true if empty no_of_db is found return false; } }); if (noDBEmpty) { Swal.fire({ icon: 'warning', title: 'Oops!', text: 'No of DB field is required and it must be whole number.', allowEnterKey: true // default value }); $(".userID").prop('checked', false); return; // Exit the function if any empty no_of_db is found } // console.log(userData);return; Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { // console.log(hdrValue);console.log(didUsersValue); console.log(uidarr);console.log(didUsersNoDB);return; // assignUsers([hdrValue, didUsersValue, uidarr, didUsersNoDB]); assignUsers(userData); } }); }); function assignUsers(userInfo) { $.ajax({ url: "api/customer_update/assign_dealer.php", type: "POST", dataType: 'json', data: { apiKey: $("#ausr-py").val(), user_data:userInfo }, success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: result.msg, allowEnterKey: true // default value }); // location.reload(); setTimeout(()=>{ location.reload(); },2500); } if(result.status==0){ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } } }); } const goBack = () => { window.history.back(); } }); PK 8F�Z�R� � u_customer_user_assigned.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return 'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/u_customer_dealer_user_assigned.php", // url: "api/customer_update/dealer_view_assigned_cu.php", type: "POST", dataType: 'json', data: { ref_num_header: url_param, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { // console.log($result); $('#total_customer_count').text(result.total_icu_assigned); $('#pending_customer_count').text(result.pending_customer_count); $('#updated_customer_count').text(result.updated_customer_count); $('#active_customer_count').text(result.total_is_active ); $('#inactive_customer_count').text(result.total_is_inactive ); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_u_customer_user_assigned_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_u_customer_user_assigned_list.php', type: "POST", dataType: 'json', data: { ref_num_header:url_param, search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").hide();//show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { ref_num_header: url_param, search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); // $('#customer_action_pending').on('click', function(event) { // $table.addClass('loading'); // $('#customer-actions').val('pending').trigger('change'); // }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_active').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('active').trigger('change'); }); $('#customer_action_inactive').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('inactive').trigger('change'); }); $('#customer_action_pending').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('pending').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter document.getElementById("dropdown-filter").addEventListener('click', function(event) { // alert("click outside"); event.stopPropagation(); }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); const goBack = () => { window.history.back(); } $(document).on('mousedown', ".is_active", function() { // Store the current value as the old value $(this).data("prev", $(this).val()); // console.log($(this).data("prev", $(this).val())) }); $(document).on('change', ".is_active", function() { let oldValue = $(this).data("prev"); // Retrieve the old value if ($(this).val() === '0') { Swal.fire({ icon: 'warning', title: 'Oops!', text: "Status field is required.", allowEnterKey: true // default value }); $(this).val(oldValue); return false; // Prevent further execution if validation fails } // console.log(oldValue) Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { let st = $(this).val(); $.ajax({ url: "api/customer_update/u_customer_dealer_user_assigned.php", type: "POST", dataType: 'json', data: { apiKey: setpy, val: $(this).attr("data-id"), attr: st }, success: function(result) { if (result.status == 1) { Swal.fire({ icon: 'success', title: 'Success!', text: result.msg, allowEnterKey: true // default value }); setTimeout(() => { Swal.close(); }, 2000); } else { Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } } }); } else { $(this).val(oldValue); } }); }); PK 8F�Z&��RG� G� ! customer_user_assigned07-30-24.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return 'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/customer_dealer_user_assigned.php", // url: "api/customer_update/dealer_view_assigned_cu.php", type: "POST", dataType: 'json', data: { ref_num_header: url_param, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { // console.log($result); $('#total_customer_count').text(result.total_icu_assigned); $('#pending_customer_count').text(result.pending_customer_count); $('#updated_customer_count').text(result.updated_customer_count); $('#active_customer_count').text(result.total_is_active); $('#inactive_customer_count').text(result.total_is_inactive); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_customer_user_assigned_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_customer_user_assigned_list.php', type: "POST", dataType: 'json', data: { ref_num_header:url_param, search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").hide();//show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { ref_num_header: url_param, search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_pending').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('pending').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#customer_action_active').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('active').trigger('change'); }); $('#customer_action_inactive').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('inactive').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter document.getElementById("dropdown-filter").addEventListener('click', function(event) { // alert("click outside"); event.stopPropagation(); }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); $(document).on('change', ".is_active", function() { if ($(this).val() =='0') { Swal.fire({ icon: 'warning', title: 'Oops!', text: "Status field is required.", allowEnterKey: true // default value }); return false; // Prevent further execution if validation fails } Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { let st = $(this).val();//($(this).is(':checked') ? 1 : 0); $.ajax({ url: "api/customer_update/dealer_view_assigned_cu.php", type: "POST", dataType: 'json', data: { apiKey: setpy,val: $(this).attr("data-id"),attr:st },success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: result.msg, allowEnterKey: true // default value }); // location.reload(); setTimeout(()=>{ Swal.close() ; location.reload(); },2000); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } } }); } }); }); const goBack = () => { window.history.back(); } PK 8F�Z�-љ� � customer_view.jsnu �[��� //GLOBALS WITTHOUT PHP var customer_record_type = "1"; var vehicle_form = false; //FUNCTIONS function initVehicleSection() { if (!vehicle_form) { vehicle_form = true; $.ajax({ url: 'include/components/customer/modal/vehicle_form.php', type: 'post', beforeSend: function() { $('#customer-vehicle-button').attr('disabled', true); }, success: function(data) { $('#vehicle_form').html(data); $.ajax({ url: 'dist/js/vehicle/vehicle_form.js', type: 'post', success: function(data) { $('#customer-vehicle-button').attr('disabled', false); initVehicle(); }, error: function() { $('#vehicle_form').text('An error occurred'); } }); }, error: function() { $('#vehicle_form').text('An error occurred'); } }); } else { $('#modal-vehicle').modal('show'); initOwnerSelect2(); } } function refreshTableLogs() { var $table = $('#logs-table') $table.bootstrapTable('destroy').bootstrapTable(); $(function() { $table.bootstrapTable('refresh', { url: 'app/table/customer_log.php' }); }) } function queryParamsLogs(params) { console.log(params) return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, customer_id: customer_record_id }; } function queryParamsSales(params) { return { search: params.search, offset: params.offset, limit: params.limit, customer_id: customer_record_id }; } function queryParamsService(params) { return { search: params.search, offset: params.offset, limit: params.limit, customer_id: customer_record_id }; } function queryParamsCorporationCustomer(params) { return { search: params.search, offset: params.offset, limit: params.limit, customer_id: customer_record_id, customer_corporation: true }; } function readCustomerSalesImage() { $.ajax({ url: "api/customer_update/customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: '7472626829226859', customer_id: customer_record_id }, beforeSend: function() { $('#loader').show(); }, success: function(result) { // result.total $('#customer-sales-image-data').html(''); $('#customer-sales-image-data').append(result.sales_image); $('#loader').hide(); } }); } function readCustomerChildren(isModal) { $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '8307826786414874', customer_id: customer_record_id }, beforeSend: function() {}, success: function(result) { var obj = jQuery.parseJSON(JSON.stringify(result)); var index = 0; if (isModal) { if (obj.length > 0) { // $('#unit_association').click(); } } else { $('#information_family_list').empty() $("#information_family_list").append( '<li class="list-group-item lbl-forms-sm-customer-main"><strong>Children/s List</strong></li>' ); if (obj.length > 0) { $('#information_family_div').show(); $('#family-page-footer').hide(); } else { $('#information_family_div').hide(); $('#family-page-footer').show(); } } var count_delay = 0; $.each(obj, function(key, value) { setTimeout(function() { if (isModal) { var item = addCustomerChildren(); let $elementFirstname = $('#' + item[0]); let $elementLastname = $('#' + item[1]); let $elementBirthday = $('#' + item[2]); let $elementMobile = $('#' + item[3]); $elementFirstname.val(value.first_name); $elementLastname.val(value.last_name); $elementBirthday.val(value.date_of_birth); $elementMobile.val(value.mobile_phone); } else { var new_mobile = (value.mobile_phone != '') ? '+63' + value .mobile_phone : ''; $("#information_family_list").append(` <li class="list-group-item lbl-forms-sm-customer-main"> <div class="row"> <div class="col-sm-6"><strong>Name: </strong> ` + value.first_name + ' ' + value.last_name + ` </div> <div class="col-sm-3"><strong>Birthday: </strong>` + value.date_of_birth + ` </div> <div class="col-sm-3"><strong>Mobile: </strong><a href="tel:` + new_mobile + `" >` + new_mobile + ` </a> </div> </div> </li> `); } }, count_delay * 250); count_delay++; }); } }); } function readCustomerAffiliations(isModal) { $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '5660696728127200', customer_id: customer_record_id }, beforeSend: function() {}, success: function(result) { var obj = jQuery.parseJSON(JSON.stringify(result)); var index = 0; if (isModal) { if (obj.length > 0) { // $('#unit_association').click(); } } else { $('#information_affiliations_list').empty() $("#information_affiliations_list").append( // '<li class="list-group-item lbl-forms-sm-customer-main"><strong>Village or Condo Homeowners Association</strong></li>' ); if (obj.length > 0) { $('#information_affiliations_div').show(); $('#affiliations-page-footer').hide(); } else { $('#information_affiliations_div').hide(); $('#affiliations-page-footer').show(); } } var count_delay = 0; $.each(obj, function(key, value) { setTimeout(function() { if (isModal) { var item = addAffiliationsItem(); let $elementCategory = $('#' + item[0]); $elementCategory.val(value .affiliation_category).trigger('change'); let $elementContent = $('#' + item[1]); var newContent = new Option(value.affiliation_content, value .affiliation_content, true, true) $elementContent.append(newContent).trigger('change'); } else { $("#information_affiliations_list").append(` <li class="list-group-item lbl-forms-sm-customer-main"> <div class="row"> <div class="col-sm-3"><strong>Category: </strong> ` + value.affiliation_category_name + ` </div> <div class="col-sm-9"><strong>Name: </strong>` + value.affiliation_content + ` </a> </div> </div> </li> `); } }, count_delay * 250); count_delay++; }); } }); } function fetchCustomerInfo(customer_record_id) { $("#profileDisplay").attr("src", "dist/img/customer/default.png"); $(".customer-data-side").text(''); $(".basic-info-name").text(''); $(".basic-info-email").text(''); $(".basic-info-mobile").text(''); $(".basic-info-type").text(''); $('#loader').show(); $('#h3-card-title').text("Customer Profile"); $('#customer-about-me').show(); $('#customer-details').show(); $('#information-customer').show(); $('#customer-vehicle').show(); $('#customer-service').show(); $('#customer-sales').show(); $('#customer-corporation-individual').show(); readCustomerInformationMain(); readCustomerInterestMain(); readCustomerContactPersonMain(); readCustomerChildren(false); readCustomerAffiliations(false); setCustomerTab(); } function setCustomerTab(){ hideCustomerTabActionButton(); removeTabActive(); var selected_tab = ''; if(isEmpty($.cookie("customer_selected_tab"))) { //set default tab $.cookie("customer_selected_tab",'custom-tabs-three-home-tab') selected_tab = $.cookie("customer_selected_tab"); }else{ selected_tab = $.cookie("customer_selected_tab"); } //show tab and content $('#'+selected_tab).addClass('active') $('#'+selected_tab+'-content').addClass('active').addClass('show') //additional condition here switch (selected_tab) { case 'custom-tabs-three-home-tab': $('#customer-info-button').show(); break; case 'custom-tabs-three-hobbies-tab': $('#customer-info-button').show(); break; case 'custom-tabs-three-family-tab': $('#customer-info-button').show(); break; case 'custom-tabs-vehicle-tab': $('#customer-vehicle-button').show(); var offset_n = 0; if (!isEmpty($.cookie("vehicle_list_offset"))) { offset_n = parseInt($.cookie("vehicle_list_offset")); } console.log('111') getVehiclesGrid(offset_n, 9); break; case 'custom-tabs-service-tab': refreshTableService(); break; case 'custom-tabs-sales-tab': refreshTableSales(); break; case 'custom-tabs-three-individuals-tab': refreshTableCorporationIndividual(); break; case 'custom-tabs-three-gallery-tab': readCustomerSalesImage(); break; case 'custom-tabs-customer-logs-tab': refreshTableLogs(); break; case 'custom-tabs-customer-activities-tab': refreshTableActivities(); break; case 'custom-tabs-insurance-tab': initTableFinance(); getVehicles(); break; } } // start --------------------- appended code -> khel (insurance tab) var arr_found = new Array(); function initTableFinance() { var $table = $('#finance-table') $table.bootstrapTable('destroy').bootstrapTable({ // onLoadSuccess: function(data) { // // detailsCount(start_date, end_date); // } }); } function refreshFinanceTable() { // alert(JSON.stringify(arr_found)); return; var $table = $('#finance-table') $(function() { $table.bootstrapTable('refresh', { // 7 url: 'app/table/finance_table.php' }); }) } function queryParamsFinanceTable(params) { return { search: params.search, offset: params.offset, limit: params.limit, plate_cs_number: arr_found, type: 7 }; } function getVehicles() { $.ajax({ url: "api/customer/customer_insurance.php", method: "POST", dataType: 'json', data: { type: 1, customer_id: customer_record_id }, beforeSend: function() { }, success: function(result) { // alert(JSON.stringify(result)); return; getFniOfVehicle(result); } }); } function getFniOfVehicle(itemsArr){ $.ajax({ url: "api/customer/customer_fni.php", method: "POST", dataType: 'json', data: { arr: itemsArr, type: 1 }, success: function(result){ if(result.length === 0){ arr_found = 0; } else { arr_found = result; } refreshFinanceTable(); } }); } function addToTable(arr){ $.ajax({ url: "api/customer/customer_fni.php", method: "POST", // dataType: 'json', data: { type: 2, arr: arr }, success: function(result){ $('#table_data').prepend(result); } }); } // end --------------------- appended code -> khel (insurance tab) function checkFieldsMain(customer_type) { if (parseInt(customer_type) === 1) { $('#information_dob_span').text('Date of birth'); $('#information_gender_div').show(); $('#information_religion_div').show(); $('#information_nationality_div').show(); $('#information_business_company_name_div').show(); $('#information_position_div').show(); $('#information_marital_status_div').show(); $('#information_spouse_div').show(); $('#div-mod-no-of-children_div').show(); // $('#information_interest_hobbies_div').show(); $('#information_profession_div').show(); $('#customer-family-tab').show(); $('#customer-corporation_individuals-tab').hide(); } else if (parseInt(customer_type) === 2) { $('#information_dob_span').text('Date established'); $('#information_gender_div').hide(); $('#information_religion_div').hide(); $('#information_nationality_div').hide(); $('#information_business_company_name_div').hide(); $('#information_position_div').hide(); $('#information_marital_status_div').hide(); $('#information_spouse_div').hide(); $('#div-mod-no-of-children_div').hide(); // $('#information_interest_hobbies_div').hide(); $('#information_profession_div').hide(); $('#customer-family-tab').hide(); $('#customer-corporation_individuals-tab').show(); } } function readCustomerInformationMain() { // return false; $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '8361020315855100', customer_id: customer_record_id }, beforeSend: function() {}, success: function(result) { var json = JSON.stringify(result); data = JSON.parse(json)[0]; if(isEmpty(data['customer_record_id'])){ // window.location.href ='customer.php'; // return; } $.each(data, function(i, n) { var excemptedFields = ["main_corporation_name", "main_first_name", "main_middle_name", "main_last_name", "information_modified_by", "information_date_modified" ]; // console.log('i :'+i+ ' n : '+n); if (excemptedFields.indexOf(i) < 0) { //excempted list $("#" + i).css('color', '') if (isEmpty(n)) { $("#" + i).text('(Not Provided)'); $("#" + i).val('(Not Provided)'); $("#" + i).css('color', 'red') } else { $("#" + i).text(n); $("#" + i).val(n); $("#" + i).trigger('change') $("#" + i).css('color', '007bff') } } else { $("#" + i).text(n); $("#" + i).val(n); $("#" + i).trigger('change') } }); // if(){ // } if(isEmpty(data['information_modified_by'])){ $("#information_modified_by_span").hide(); }else{ $("#information_modified_by_span").show(); } if(isEmpty(data['information_date_modified'])){ $("#information_date_modified_span").hide(); }else{ $("#information_date_modified_span").show(); } customer_record_type = data['customer_type_id']; checkFieldsMain(customer_record_type); $(".contact-click").attr("href", "tel:" + $('#main_customer_mobile').text()) $(".landline-click").attr("href", "tel:" + $('#main_customer_landline').text()) $(".contact2-click").attr("href", "tel:" + $('#main_customer_mobile_2').text()) $(".business-click").attr("href", "tel:" + $('#main_customer_business_mobile').text()) $(".residential-click").attr("href", "tel:" + $('#main_customer_home_mobile').text()) $(".viber-click").attr("href", "viber://chat?number=" + $('#main_viber').text()) $(".facebook-click").attr("href", "http://www.facebook.com/" + $('#main_facebook').text()) $(".instagram-click").attr("href", "http://instagram.com/_u/" + $('#main_instagram').text()) $(".whatsapp-click").attr("href", "https://wa.me/" + $('#main_whatsapp').text()) $(".telegram-click").attr("href", "https://t.me/" + $('#main_telegram').text()) $(".website-click").attr("href", "http://" + $('#main_website_link').text()) $(".email-click").attr("href", "mailto:" + $('#main_email').text()) $(".email2-click").attr("href", "mailto:" + $('#main_customer_email_2').text()) $("#profileDisplay").attr("src", "dist/img/customer/" + data['photo']); $("#profileDisplay_pop").attr("href", "dist/img/customer/" + data['photo']); $('#loader').hide(); }, error: function(xhr, status, error) { $('#loader').hide(); // back(); sweetAlertSimple('error', 'Oops...', 'Error has occurred, Try again...'); toastr.remove(); toastr.error('Error has occurred, Try again...'); } }); } function readCustomerInterestMain() { $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '6579442853321353', customer_id: customer_record_id }, beforeSend: function() {}, success: function(result) { var obj = jQuery.parseJSON(JSON.stringify(result)); var index = 0; $('#information_interest_hobbies_list').empty() $("#information_interest_hobbies_list").append( '<li class="list-group-item lbl-forms-sm-customer-main"><strong>Interest/Hobbies</strong></li>' ); if (obj.length > 0) { $('#information_interest_hobbies_div').show(); } else { $('#information_interest_hobbies_div').hide(); } var count_delay = 0; $.each(obj, function(key, value) { setTimeout(function() { $("#information_interest_hobbies_list").append(` <li class="list-group-item lbl-forms-sm-customer-main"> <div class="row"> <div class="col-sm-6"> ` + value.interest_content + ` </div> <div class="col-sm-6"> <span class="badge badge-success"> ` + value.interest_category_name + ` </span> </div> </div> </li> `); }, count_delay * 250); count_delay++; }); } }); } function readCustomerContactPersonMain() { $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '4788616921820004', customer_id: customer_record_id }, beforeSend: function() {}, success: function(result) { var obj = jQuery.parseJSON(JSON.stringify(result)); var index = 0; $('#information_contact_person_list').empty() $("#information_contact_person_list").append( '<li class="list-group-item lbl-forms-sm-customer-main"><strong>Contact Person</strong></li>' ); if (obj.length > 0) { $('#information_contact_person_div').show(); } else { $('#information_contact_person_div').hide(); } var count_delay = 0; $.each(obj, function(key, value) { setTimeout(function() { $("#information_contact_person_list").append(` <li class="list-group-item lbl-forms-sm-customer-main"> <div class="row"> <div class="col-sm-5"> ` + value.full_name + ` </div> <div class="col-sm-3"> <a href="tel:` + ((isEmpty(value.mobile_phone)) ? '' : value.mobile_phone) + `"> ` + ((isEmpty(value.mobile_phone)) ? '' : '+63' + value.mobile_phone) + ` </a> </div> <div class="col-sm-4"> <a href="mailto:` + value.email + `"> ` + value.email + ` </a> </div> </div> </li> `); }, count_delay * 250); count_delay++; }); } }); } function hideCustomerTabActionButton() { $('#customer-info-button').hide(); $('#customer-gallery-button').hide(); $('#customer-vehicle-button').hide(); } function removeTabActive() { $('.customer-tab').removeClass('active') $('.customer-tab-content').removeClass('active').removeClass('show') } function gotoOffset(n) { $.cookie("vehicle_list_offset", n); // console.log('222') getVehiclesGrid(n, 9); } function getVehiclesGrid(offset, limit) { $.ajax({ url: "app/table/vehiclev2.php", type: "POST", dataType: 'json', data: { customer_id: customer_record_id, grid: 1, offset: offset, limit: limit }, beforeSend: function() { $('#loader-vehicle').show(); }, success: function(result) { // result.total $('#customer-owned-vehicle').html(''); $('#customer-owned-vehicle').append(result.vehicle_list); $('#customer-owned-vehicle-paging').html(''); if (result.total <= 0) { $('#customer-owned-vehicle-paging').append(result.vehicle_list_paging); } if (result.grid_offset > 6) { $('#customer-owned-vehicle-paging').append(result.vehicle_list_paging); } $('#loader-vehicle').hide(); } }); } function customerVehicleInfo(grid_vehicle_id) { $.cookie("vehicle_selected_tab",'custom-tabs-three-home-tab') window.location.href = "vehicle_view.php?q=" + grid_vehicle_id; } function refreshTableService() { var $table = $('#service-table') $table.bootstrapTable('destroy').bootstrapTable(); $(function() { $table.bootstrapTable('refresh', { url: 'app/table/service.php' }); }) } function refreshTableCorporationIndividual() { var $table = $('#corporation-individual') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_customer_list.php' }); }) } function refreshTableSales() { var $table = $('#sales-table') $table.bootstrapTable('destroy').bootstrapTable(); $(function() { $table.bootstrapTable('refresh', { url: 'app/table/sales.php' }); }) } function back() { window.history.back(); } function customerModal() { $('#proceed-button').text("Save changes"); $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); if (parseInt(customer_record_type) === 1) { $('#modal-title').text("Edit Customer Information (Individual)"); checkFieldsModal(true); } else if (parseInt(customer_record_type) === 2) { $('#modal-title').text("Edit Customer Information (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); //fetch data and put to fields readCustomerProfile(); } function readCustomerProfile() { readCustomerInformation(); readCustomerProfileDataSource(); readCustomerContactPerson(); readCustomerChildren(true); readCustomerProfileInterest(); readCustomerAffiliations(true); } function readCustomerInformation() { $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '3463916057587803', customer_id: customer_record_id }, beforeSend: function() {}, success: function(result) { $('.customer-modal-overlay').hide(); $('#proceed-button').attr('disabled', false); var json = JSON.stringify(result); data = JSON.parse(json)[0]; $.each(data, function(i, n) { console.log('dito') console.log('i :'+i+' n:'+n); // if(i =='mod-other-mobile-number'){} if (i == 'mod-nature-of-business' && n != 0) { var newOption = new Option(data['mod-nature-of-business-name'], data[ 'mod-nature-of-business-name'], true, true); $("#" + i).append(newOption).trigger('change'); } else if (i == 'mod-preferred-moc' && n != 0) { var newOption = new Option(data['mod-preferred-moc-name'], data['mod-preferred-moc-name'], true, true); $("#" + i).append(newOption).trigger('change'); } else if (i == 'mod-dd-profession' && n != 0) { var newOption = new Option(data['mod-dd-profession-name'], data[ 'mod-dd-profession-name'], true, true); $("#" + i).append(newOption).trigger('change'); } else if (i == 'mod-business-company' && n != 0) { var newOption = new Option(data['mod-business-company-name'], data[ 'mod-business-company'], true, true); $("#" + i).append(newOption).trigger('change'); console.log(newOption); } else if (i == 'aha-status' ) { if(parseInt(data['aha-status'])){ $('#aha-status').prop('checked', true).trigger('change') $('#aha-status').val('1'); } } else { if(i =='mod-other-mobile-number1' && n.length>0){ $("#countInputMobile").val(1); var count =$("#countInputMobile").val(); appendOtherContact(count); } if(i =='mod-other-mobile-number2' && n.length>0){ $("#countInputMobile").val(2); var count =$("#countInputMobile").val(); appendOtherContact(count); } if(i =='mod-other-email1' && n.length > 0){ // $("#countInputMobile").val(2); // var count =$("#countInputMobile").val(); appendOtherEmail(1); } if(i =='mod-other-email2' && n!=null && n.length > 0){ // $("#countInputMobile").val(2); // var count =$("#countInputMobile").val(); appendOtherEmail(2); } $("#" + i).val(n); $("#" + i).trigger('change') } }); } }); } //MODIFY function appendOtherContact(count) { // count++; // $("#countInputMobile").val(count); let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // console.log('count :'+inputMobLengh); if(inputMobLengh <2){ var inputCount = $("#countInputMobile").val(); let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm', 'id':'mod-other-mobile-number','type':'number','maxlength':'10','json-modal':'true','oninput':'"this.value=this.value.slice(0,this.maxLength)"'}); let label = $('<label></label>').attr({'for': 'Other Mobile ','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); inputMobLengh = inputMobLengh-1; if(inputMobLengh<1){ $("#btn-add-mobile").show(); } else{ $("#btn-add-mobile").hide(); } }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh<1){ $("#btn-add-mobile").show(); } else{ $("#btn-add-mobile").hide(); } // $('#mod-contact-div input[name="mob[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); // }); }//end if } function appendOtherEmail(count){ if($('#email-add input[name="mob-email[]"]').length <=1){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email'+count,'class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); if(($('#email-add input[name="mob-email[]"]').length)>=3){ $("#btn-add-email").hide(); } else { $("#btn-add-email").show(); } }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); if(($('#email-add input[name="mob-email[]"]').length)>=2){ $("#btn-add-email").hide(); } else { $("#btn-add-email").show(); } }//end if } function readCustomerProfileDataSource() { $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '3099751888433363', customer_id: customer_record_id }, beforeSend: function() {}, success: function(result) { var obj = jQuery.parseJSON(JSON.stringify(result)); var index = 0; var count_delay = 0; $.each(obj, function(key, value) { setTimeout(function() { var dataSourceItem = addDataSourceItem(); let $dataSourceCustomerNo = $('#' + dataSourceItem[0]); $dataSourceCustomerNo.val(value.customer_dms_id); let $dataSourceDMS = $('#' + dataSourceItem[1]); $dataSourceDMS.val(value.dms_id).trigger('change'); let $dataSourceCompany = $('#' + dataSourceItem[2]); var newCompanyContent = new Option(value.company_name, value .company_id, true, true) $dataSourceCompany.append(newCompanyContent).trigger('change'); let $dataSourceDealer = $('#' + dataSourceItem[3]); var newDealerContent = new Option(value.dealer_name, value .dealer_id, true, true) $dataSourceDealer.append(newDealerContent).trigger('change'); }, count_delay * 250); count_delay++; }); } }); } function readCustomerContactPerson() { $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '4788616921820004', customer_id: customer_record_id }, beforeSend: function() {}, success: function(result) { var obj = jQuery.parseJSON(JSON.stringify(result)); var index = 0; var count_delay = 0; $.each(obj, function(key, value) { setTimeout(function() { var item = addCustomerContactPerson(); let $elementFullname = $('#' + item[0]); let $elementEmail = $('#' + item[1]); let $elementMobile = $('#' + item[2]); $elementFullname.val(value.full_name); $elementEmail.val(value.email); $elementMobile.val(value.mobile_phone); }, count_delay * 250); count_delay++; }); } }); } function readCustomerProfileInterest() { $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '6579442853321353', customer_id: customer_record_id }, beforeSend: function() {}, success: function(result) { var obj = jQuery.parseJSON(JSON.stringify(result)); var index = 0; if (obj.length > 0) { // $('#intereset_hobbies_div').click(); } var count_delay = 0; $.each(obj, function(key, value) { setTimeout(function() { var interestItem = addInterestItem(); let $elementInterestCategory = $('#' + interestItem[0]); // let val = $elementInterestCategory.find("option:contains('" + value // .interest_category + "')").val() $elementInterestCategory.val(value .interest_category).trigger('change'); let $elementInterestContent = $('#' + interestItem[1]); var newInterestContent = new Option(value.interest_content, value .interest_content, true, true) $elementInterestContent.append(newInterestContent).trigger( 'change'); }, count_delay * 250); count_delay++; }); } }); } function removeCustomer(customer_record_id){ Swal.fire({ icon: 'question', html: 'Are you sure you want to remove this customer?', showDenyButton: false, showCancelButton: true, confirmButtonText: `Confirm`, denyButtonText: `Don't Confirm`, }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '3695340036334748', customer_id: customer_record_id }, beforeSend: function() { sweetAlertSimple('info', 'Oops...', 'Removing customer...') }, success: function(result) { if(parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); var url = location_url+"customer.php"; window.location.href = url; }else{ sweetAlertSimple('error', 'Oops...', result.message) } }, error: function() { sweetAlertSimple('error', 'Oops...', 'Error has been occurred, please try again.') } }); } else if (result.isDenied) { // Swal.fire('', 'Changes are not saved', 'info') } }) } //END FUNCTIONS $(function() { var count =1; fetchCustomerInfo(customer_record_id); $('#corporation-individual').on('click-cell.bs.table', function(field, value, row, $el) { if (value == 'email_1' || value == 'mobile_phone_1') { return; } // $.cookie("tab_open_view", 1); $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); window.location.href = "customer_view.php?q=" + $el.id; }); $('.customer-tab').on('click',function(event){ console.log(this.id); $.cookie("customer_selected_tab", this.id); setCustomerTab(); }); $('#service-table').on('click-cell.bs.table', function(field, value, row, $el) { // window.location.hash = 'data_information'; //Do the Ajax request for getting customer full profile information var id = $el.id; var customer_id = $el.customer_id; var ro_number = $el.ro_number; $('#loader').show(); $.cookie("service_customer_id", customer_id); $.cookie("service_service_id", id); $.cookie("service_ro_number", ro_number); var url = location_url+"service.php#service_data"; window.location.href = url; }); $('#sales-table').on('click-cell.bs.table', function(field, value, row, $el) { //Do the Ajax request for getting customer full profile information var id = $el.id; var customer_id = $el.customer_id; var vehicle_id = $el.vehicle_id; $('#loader').show(); $.cookie("sale_customer_id", customer_id); $.cookie("sale_sale_id", id); $.cookie("sale_vehicle_id", vehicle_id); var url = location_url+"sales.php#sales_data"; window.location.href = url; }); $(document).on('click', '[data-toggle="lightbox"]', function(event) { event.preventDefault(); $(this).ekkoLightbox({ alwaysShowClose: false, loadingMessage: "Loading…", }); }); $('#customer-vehicle-button').click(function() { initVehicleSection(); }) $('#proceed-button').on("click", function() { // alert('fire update'); // validate all data if (parseInt(customer_record_type) === 1) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else if (parseInt(customer_record_type) === 2) { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (parseInt(customer_record_type) === 1) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error mobile contact');return; $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } //MODIFY//check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { $("#mod-other-mobile-number1").prop('required',false); } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { // console.log(''+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } //END MODIFY } else if (parseInt(customer_record_type) === 2) { if(isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val()) ) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } //MODIFY if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } else { $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } if($('#mod-other-email1').length > 0 && $('#mod-other-email1').val() != '') { if (!isEmpty($('#mod-other-email1').val())) { if (!isEmail($('#mod-other-email1').val())) { addCustomerModalTabSelectedTab(2); $('#mod-other-email1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); return; } } if($('#mod-other-email1').val() == $('#mod-email').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate email address.'); return; } }else if($('#mod-other-email1').length ===1 && $('#mod-other-email1').val()===''){ // console.log('accept validation');return; $("#mod-other-email1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-email1').focus(); return; }else { $("#mod-other-email1").prop('required',false); // sweetAlertSimple('error', 'Oops...', 'Field required.'); // $('#mod-other-email2').focus(); // return; } if($('#mod-other-email2').length > 0 && $('#mod-other-email2').val() != '') { if (!isEmpty($('#mod-other-email2').val())) { if (!isEmail($('#mod-other-email2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-other-email2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); return; } } if($('#mod-other-email2').val() == $('#mod-email').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate email address.'); return; } if($('#mod-other-email1').val() == $('#mod-other-email2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate email address.'); return; } } else if($('#mod-other-email2').length ===1 && $('#mod-other-email2').val()===''){ // console.log('accept validation');return; $("#mod-other-email2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-email1').focus(); return; } else { $("#mod-other-email2").prop('required',false); // sweetAlertSimple('error', 'Oops...', 'Field required.'); // $('#mod-other-email2').focus(); // return; } //END MODIFY var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } $.ajax({ url: "api/customer_update/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '8906433219679554', customer_id: customer_record_id, customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); fetchCustomerInfo(customer_record_id); //error city dropdown after call $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; // window.reload(); }, error: handleError }); setTimeout(function(){ // window.location.reload(); },500) }); $('#customer_delete_action').click(function() { removeCustomer(customer_record_id) }) $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); //MODIFY //add mobile number dynamically $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-addinput[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); //END MODIFY });PK 8F�Z`��w�� �� assigned_customer_update.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return '';//'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''//'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/assigned_customer_user.php", //dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: '8666264351338448' }, beforeSend: function() {}, success: function(result) { // a=result.total_icu.replace(/\,/g,''); // 1125, but a string, so convert it to number // total_avail_inactive=parseInt(a,10); // $("#no_assign").attr({ // "max" : total_avail_inactive, // "min" : 1 // }); // $('#total_customer_count').text(result.total_icu); // if(result.total_icu ==0) // { // $("#sl_company").attr('disabled', true); // $("#btn-submit-manually").attr('disabled', true); // } // else // { // $("#sl_company").attr('disabled', false); // $("#btn-submit-manually").attr('disabled', false); // } // $('#new_customer_count').text(result.new_customer_count); // $('#updated_customer_count').text(result.updated_customer_count); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { // url: 'app/table/bt_dealer_assignment_update_list.php' url: 'app/table/bt_assigned_customer_update.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_assigned_customer_update.php', type: "POST", dataType: 'json', data: { search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }; } // function customerModal(isIndividual) { // new_customer_is_individual = isIndividual; // $('#proceed-button').text("Add Customer"); // $('.customer-modal-overlay').hide(); // if (isIndividual) { // $('#modal-title').text("New Customera (Individual)"); // checkFieldsModal(true); // } else { // $('#modal-title').text("New Customerb (Corporation)"); // checkFieldsModal(false); // } // resetCustomerModal(); // $("#addRowDataSource").click(); // } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); // $('#gender').off('change.mychange').on('change.mychange', function() { // $('#customer-actions').off('change.mychange'); // $('#customer-actions').val('').trigger('change') // addFilterListenerCustomerAction(); // refreshTableCustomer(); // }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // // alert("click outside"); // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); const goBack = () => { window.history.back(); } $(document).on('click', ".rmv-bt", function() { Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { $.ajax({ url: "api/customer_update/assigned_customer_update.php", type: "POST", dataType: 'json', data: { apiKey: skey,val: $(this).val() },success: function(response) { if(response.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: response.msg, allowEnterKey: true // default value }); // location.reload(); setTimeout(()=>{ Swal.close() ; // setTimeout(function () { // Swal.close() // }, 2000) },2000); location.reload(); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: response.msg, allowEnterKey: true // default value }); } } }); } }); }); PK 8F�Z 68U�� �� customer_assigned_user_form.jsnu �[��� var force_update = 0; var force_update_reason = ""; function removeextra() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9a-zA-Z]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function removeextranumonly() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9()-]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function getCustomerAllModalData() { var /* Create an object. */ obj = {}, /* Create a variable that references the current object (default → obj). */ ref = obj; /* Iterate over every input. */ $("#modal-customer :input").each(function () { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute("nodetype") == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute("json-modal") == "true") { ref[id] = $(this).val(); } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function sweetAlertSimple(icon, title, text) { // Swal.fire({ // icon: icon, // title: title, // text: text, // allowEnterKey: true // default value // }) toastr.remove(); switch (icon) { case "success": toastr.success(text); break; case "info": toastr.info(text); break; case "warning": toastr.warning(text); break; case "error": toastr.error(text); break; } } function getAllDataSourceTableData() { var $table = $("#data-source-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { var new_header = $(this).html().replace(/\s/g, "_").replace(/\./g, ""); header.push(new_header); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { if (header[i] == "Customer_No") { var key = header[i], value = $(this).find("input").val(); row[key] = value; } else { var key = header[i], value = $(this).find("select").val(); row[key] = value; } }); rows.push(row); }); return rows; } function checkIfDataSourceIncomplete() { rows = getAllDataSourceTableData(); var dataSourceJsonRow = rows; var hasMatch = true; for (var index = 0; index < dataSourceJsonRow.length; ++index) { var dataSourceJson = dataSourceJsonRow[index]; if ( // dataSourceJson.Customer_No == "" || dataSourceJson.DMS == "" || dataSourceJson.Company == "" || dataSourceJson.Dealer == "" ) { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function handleError(xhr, status, error) { //hide loader sweetAlertSimple("error", "Oops...", "Error has occurred, Try again..."); $("#proceed-button").attr("disabled", false); $(".customer-modal-overlay").hide(); force_update = 0; force_update_reason = ""; } function refreshModalCities() { $.ajax({ url: "api/city/city.php", type: "GET", dataType: "json", data: { apiKey: "5881641680981247", }, beforeSend: function () { $("#mod-dd-city-1").prop("disabled", true); $("#mod-dd-city-2").prop("disabled", true); }, success: function (result) { $("#mod-dd-city-1").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-2").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-1").prop("disabled", false); $("#mod-dd-city-2").prop("disabled", false); }, }); } function checkIfChildrenIncomplete() { rows = getAllChildrenTableData(); var childrenJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; for (var index = 0; index < childrenJsonRow.length; ++index) { var childrenJson = childrenJsonRow[index]; if ( childrenJson.Firstname == "" || childrenJson.Lastname == "" || childrenJson.Birthday == "" ) { hasMatch[0] = false; break; } if (!isEmpty(childrenJson.Mobile)) { if (childrenJson.Mobile.length < 10) { hasMatch[1] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllChildrenTableData() { var $table = $("#children-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function isEmail(email) { var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return regex.test(email); } function isEmpty(string) { var flag = false; try { if (string.trim() == "") { flag = true; } else if (string == null) { flag = true; } else if (typeof string === "undefined") { flag = true; } } catch (err) { // console.log(err); flag = true; } return flag; } function checkIfContactPersonIncomplete() { rows = getAllContactPersonTableData(); var contactPersonJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; hasMatch[2] = true; for (var index = 0; index < contactPersonJsonRow.length; ++index) { var contactPersonJson = contactPersonJsonRow[index]; if ( contactPersonJson.Fullname == "" /* || contactPersonJson.Lastname == "" || contactPersonJson.Mobile == ""*/ ) { hasMatch[0] = false; break; } if (contactPersonJson.Email != "") { if (!isEmail(contactPersonJson.Email)) { hasMatch[1] = false; break; } } if (!isEmpty(contactPersonJson.Mobile)) { if (contactPersonJson.Mobile.length < 10) { hasMatch[2] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllContactPersonTableData() { var $table = $("#contact-person-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function addCustomerChildren() { var children_list = document.getElementById("children-list"); const children_list_base = document.querySelector( "#children-list-clone tbody tr" ); children_list.appendChild(children_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var ChildrenIdDateNow = uniqId(); var newChildrenFirstnameId = "children-firstname-" + ChildrenIdDateNow; var newChildrenLastnameId = "children-lastname-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "div-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "append-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayId = "children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "children-birthday-div-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "children-birthday-append-" + ChildrenIdDateNow; var newChildrenMobileId = "children-mobile-append-" + ChildrenIdDateNow; var item = []; item[0] = newChildrenFirstnameId; item[1] = newChildrenLastnameId; item[2] = newChildrenBirthdayId; item[3] = newChildrenMobileId; $("#mod-children-firstname").attr("id", newChildrenFirstnameId); $("#mod-children-lastname").attr("id", newChildrenLastnameId); $("#mod-children-mobile").attr("id", newChildrenMobileId); $("#mod-children-birthdate") .attr("id", newChildrenBirthdayId) .data("target", "#" + newChildrenBirthdayDivId) .inputmask(); $("#mod-children-birthdate-append") .attr("id", newChildrenBirthdayAppendId) .data("target", "#" + newChildrenBirthdayDivId); $("#mod-children-birthdate-div") .attr("id", newChildrenBirthdayDivId) .datetimepicker({ format: "L", }); return item; } function addCustomerContactPerson() { var contact_person_list = document.getElementById("contact-person-list"); const contact_person_list_base = document.querySelector( "#contact-person-list-clone tbody tr" ); contact_person_list.appendChild(contact_person_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var contactPersonIdDateNow = uniqId(); var newContactPersonFullnameId = "contact-person-fullname-" + contactPersonIdDateNow; var newContactPersonFirstnameId = "contact-person-firstname-" + contactPersonIdDateNow; var newContactPersonLastnameId = "contact-person-lastname-" + contactPersonIdDateNow; var newContactPersonEmailId = "contact-person-email-" + contactPersonIdDateNow; var newContactPersonMobileId = "contact-person-mobile-" + contactPersonIdDateNow; var item = []; item[0] = newContactPersonFullnameId; item[1] = newContactPersonEmailId; item[2] = newContactPersonMobileId; $("#modal-contact-person-fullname").attr("id", newContactPersonFullnameId); $("#modal-contact-person-email").attr("id", newContactPersonEmailId); $("#modal-contact-person-mobile").attr("id", newContactPersonMobileId); return item; } function addRowInterest() { $("#addRow").click(function () { if ( !checkIfInterestIncomplete() && $("#interest-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the interest/hobbies details first" ); } else { addInterestItem(); } }); $("#interest-list").on("click", ".btnRemove", function () { $(this).closest("tr").remove(); }); } function getAllInterestTableData() { var $table = $("#interest-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfInterestIncomplete() { rows = getAllInterestTableData(); var interestJsonRow = rows; var hasMatch = true; for (var index = 0; index < interestJsonRow.length; ++index) { var interestJson = interestJsonRow[index]; if (interestJson.Category == "" || interestJson.Interest == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function addRowAffiliations() { $("#addRowAffiliations").click(function () { if ( !checkIfAffiliationsIncomplete() && $("#affiliations-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the affiliation details first" ); } else { addAffiliationsItem(); } }); $("#affiliations-list").on("click", ".btnRemoveAffiliations", function () { $(this).closest("tr").remove(); }); } function getAllAffiliationsTableData() { var $table = $("#affiliations-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html().replace(/\s/g, "_").replace(/\./g, "")); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfAffiliationsIncomplete() { rows = getAllAffiliationsTableData(); var jsonRow = rows; var hasMatch = true; for (var index = 0; index < jsonRow.length; ++index) { var json = jsonRow[index]; if (json.Category == "" || json.Affiliations == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function refreshModalReligion() { $.ajax({ url: "api/religion/religion.php", method: "POST", data: { apiKey: "2011315786548487", }, cache: false, beforeSend: function () {}, success: function (result) { var obj = jQuery.parseJSON(result); $("#mod-dd-religion").select2({ tags: true, placeholder: "Select Religion", allowClear: true, data: obj, }); }, }); } function resetCustomerModal() { $("#mod-dd-nationality").val("608").trigger("change"); $("#interest-list-table > tbody").empty(); $("#affiliations-list-table > tbody").empty(); $("#contact-person-list-table > tbody").empty(); $("#children-list-table > tbody").empty(); $("#data-source-list-table > tbody").empty(); $("#educational-bg-list-table > tbody").empty(); $("#car-clubs-list-table > tbody").empty(); $("#unit-association-list-table > tbody").empty(); $("#political-clubs-list-table > tbody").empty(); $("#network-marketing-list-table > tbody").empty(); $("#media-publications-list-table > tbody").empty(); $("#sme-groups-list-table > tbody").empty(); $("#fraternities-sororities-list-table > tbody").empty(); $("#facebook-groups-list-table > tbody").empty(); $("#celebrity-influencers-list-table > tbody").empty(); addCustomerModalTabSelectedTab(1); } function checkFieldsModal(isIndividual) { if (isIndividual) { $(".children-stepper").show(); $(".interest-stepper").show(); $(".interest-list").show(); $("#div-mod-firstname").show(); $("#div-mod-middlename").show(); $("#div-mod-lastname").show(); $("#div-mod-suffix").show(); $("#div-corporation-name").hide(); $("#mod-birthdate-label").text("Date of birth"); $("#div-mod-gender").show(); $("#div-mod-nationality").show(); $("#div-mod-occupation").show(); $("#div-mod-marital-status").show(); // $('#mod-contact-corporation-div').hide(); // $('#mod-contact-div').show(); $("#div-mod-spouse").show(); $("#div-mod-no-of-children").show(); $("#div-mod-business-company").show(); $("#div-mod-position").show(); $("#div-mod-religion").show(); $("#div-mod-profession").show(); $("#div-corporation-name").hide(); $("#div-mod-age-of-company").hide(); $("#educational_bg_div").show(); } else { $(".children-stepper").hide(); $(".interest-stepper").hide(); $(".interest-list").hide(); $("#div-mod-firstname").hide(); $("#div-mod-middlename").hide(); $("#div-mod-lastname").hide(); $("#div-mod-suffix").hide(); $("#div-corporation-name").show(); $("#mod-birthdate-label").text("Date Established"); $("#div-mod-gender").hide(); $("#div-mod-nationality").hide(); $("#div-mod-occupation").hide(); $("#div-mod-marital-status").hide(); // $('#mod-contact-corporation-div').show(); // $('#mod-contact-div').hide(); $("#div-mod-spouse").hide(); $("#div-mod-no-of-children").hide(); $("#div-mod-business-company").hide(); $("#div-mod-position").hide(); $("#div-mod-religion").hide(); $("#div-mod-profession").hide(); $("#div-mod-date-established").show(); $("#div-mod-age-of-company").show(); $("#educational_bg_div").hide(); } } function addCustomerModalTabSelectedTab(type) { $("#customer-modal-tab .nav-link").removeClass("active"); $("#customer-modal-tab-content .tab-pane").removeClass("show"); $("#customer-modal-tab-content .tab-pane").removeClass("active"); switch (type) { case 1: $("#customer-modal-tab-information").addClass("active"); $("#customer-modal-information").addClass("active"); $("#customer-modal-information").addClass("show"); break; case 2: $("#customer-modal-tab-contact").addClass("active"); $("#customer-modal-contact").addClass("active"); $("#customer-modal-contact").addClass("show"); break; case 3: $("#customer-modal-tab-children").addClass("active"); $("#customer-modal-children").addClass("active"); $("#customer-modal-children").addClass("show"); break; case 4: $("#customer-modal-tab-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("show"); break; case 5: $("#customer-modal-tab-interest").addClass("active"); $("#customer-modal-interest").addClass("active"); $("#customer-modal-interest").addClass("show"); break; } } function uniqId() { return Math.round(new Date().getTime() + Math.random() * 100); } function checkIfEmpty(value, row, index) { if (value == "" || value == "-" || value == null) { return "<span style='color:red;'> (Not Provided) </span>"; } return value; } function getCookie(name) { var match = document.cookie.match(RegExp("(?:^|;\\s*)" + name + "=([^;]*)")); return match ? match[1] : null; } function imageFormatter(value, row, index) { return ( '<img width="50px" height="50px" class="user-image img-circle elevation-2" src="dist/img/thumbnail/' + value + '" />' ); } function initToolTip() { var bootstrapTooltip = $.fn.tooltip.noConflict(); $.fn.bstooltip = bootstrapTooltip; $(".tooltip-me").bstooltip(); } function tableMobileFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='tel:" + value + "'>" + value + "</a>"; } function tableNameFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } //ACTIVE LINK TRIGGER EDIT return "<a href='customer_update_view.php?q=" + row.id + "'>" + value + "</a>"; } function tableEmailFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='mailto:" + value + "'>" + value + "</a>"; } function addDataSourceItem() { var data_source = document.getElementById("data-source-list"); const data_source_base = document.querySelector( "#data-source-list-clone tbody tr" ); data_source.appendChild(data_source_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var dataSourceIdDateNow = uniqId(); var newDataSourceCustomerNoId = "data-source-customer-no-" + dataSourceIdDateNow; var newDataSourceDmsId = "data-source-dms-" + dataSourceIdDateNow; var newDataSourceCompanyId = "data-source-company-" + dataSourceIdDateNow; var newDataSourceDealerId = "data-source-dealer-" + dataSourceIdDateNow; var dataSourceItem = []; dataSourceItem[0] = newDataSourceCustomerNoId; dataSourceItem[1] = newDataSourceDmsId; dataSourceItem[2] = newDataSourceCompanyId; dataSourceItem[3] = newDataSourceDealerId; $("#input-modal-customer-no").attr("id", newDataSourceCustomerNoId); $("#" + newDataSourceCustomerNoId) .on("keyup", removeextra) .blur(removeextra); $("#" + newDataSourceCustomerNoId).on("keypress", function (e) { var regex = new RegExp("^[0-9a-zA-Z]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; }); $("#select-modal-dms").attr("id", newDataSourceDmsId).select2({ placeholder: "Select DMS", allowClear: true, }); $("#select-modal-company") .attr("id", newDataSourceCompanyId) .select2({ placeholder: "Select Company", allowClear: true, language: { noResults: function () { return "Select DMS first"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/company/company.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term dms_id: $("#" + newDataSourceDmsId).val(), apiKey: "3568127986733141", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-preferred-moc").select2({ placeholder: "Select mode of contact", allowClear: true, tags: false, minimumResultsForSearch: -1, language: { noResults: function () { return "Select mode of contact"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/mode_of_contact/mode_of_contact.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "1557741601453763", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-business-company").select2({ placeholder: "Search Company by name, email and mobile", allowClear: true, language: { noResults: function () { return "Search Company by name, email and mobile"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/customer/customerv2.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "3975247589935894", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#select-modal-dealer") .attr("id", newDataSourceDealerId) .select2({ placeholder: "Select Dealer", allowClear: true, language: { noResults: function () { return "Search or enter dealer name"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/dealer/dealer.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6209267133015033", company_id: $("#" + newDataSourceCompanyId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newDataSourceDmsId).on("change", function (event) { $("#" + newDataSourceCompanyId) .val("") .trigger("change"); }); $("#" + newDataSourceCompanyId).on("change", function (event) { $("#" + newDataSourceDealerId) .val("") .trigger("change"); }); return dataSourceItem; } function addInterestItem() { // CREATE ROW var interest_list = document.getElementById("interest-list"); const interest_list_base = document.querySelector( "#interest-list-clone tbody tr" ); var interestItem = []; interest_list.appendChild(interest_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var InterestIdDateNow = uniqId(); var newInterestCategoryId = "interest-category-" + InterestIdDateNow; var newInterestContentId = "interest-content-" + InterestIdDateNow; interestItem[0] = newInterestCategoryId; interestItem[1] = newInterestContentId; // alert(interestItem.pop(0)); // alert(interestItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category").attr("id", newInterestCategoryId).select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content") .attr("id", newInterestContentId) .select2({ tags: true, placeholder: "Select", allowClear: true, language: { noResults: function () { return "Search or enter interest"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter interest", ajax: { url: "api/interest_hobbies/interest_hobbies.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "5068581874181452", interestCategory: $("#" + newInterestCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newInterestCategoryId).on("select2:select", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); $("#" + newInterestCategoryId).on("select2:unselecting", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); return interestItem; // CREATE ROW } function addAffiliationsItem() { // CREATE ROW var affiliations_list = document.getElementById("affiliations-list"); const affiliations_list_base = document.querySelector( "#affiliations-list-clone tbody tr" ); var affiliationsItem = []; affiliations_list.appendChild(affiliations_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var affiliationsIdDateNow = uniqId(); var newaffiliationsCategoryId = "affiliations-category-" + affiliationsIdDateNow; var newaffiliationsContentId = "affiliations-content-" + affiliationsIdDateNow; affiliationsItem[0] = newaffiliationsCategoryId; affiliationsItem[1] = newaffiliationsContentId; // alert(affiliationsItem.pop(0)); // alert(affiliationsItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category-affiliations") .attr("id", newaffiliationsCategoryId) .select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content-affiliations") .attr("id", newaffiliationsContentId) .select2({ tags: true, placeholder: "Search or enter affiliations", allowClear: true, language: { noResults: function () { return "Search or enter affiliations"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter affiliations", ajax: { url: "api/affiliations/affiliations.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8048636851659915", affiliationsCategory: $("#" + newaffiliationsCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); // $('#' + newaffiliationsCategoryId).on('select2:select', function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); // $('#' + newaffiliationsCategoryId).on("select2:unselecting", function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); return affiliationsItem; // CREATE ROW } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function () { $("#addRowDataSource").click(function () { if ( !checkIfDataSourceIncomplete() && $("#data-source-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data source details first" ); } else { addDataSourceItem(); } }); $("#data-source-list").on("click", ".btnRemoveDataSource", function () { if ($("#data-source-list-table tbody tr").length < 2) { sweetAlertSimple("error", "Oops...", "Need at least 1 data source"); } else { $(this).closest("tr").remove(); } }); $("#addRowChildren").click(function () { var validate_data_children_list = checkIfChildrenIncomplete(); if ( !validate_data_children_list[0] && $("#children-list-table tbody tr").length > 0 ) { sweetAlertSimple("error", "Oops...", "Complete the child details first"); } else if (!validate_data_children_list[1]) { sweetAlertSimple("error", "Oops...", "Children data invalid mobile"); } else { addCustomerChildren(); } }); $("#children-list").on("click", ".btnRemoveChildren", function () { $(this).closest("tr").remove(); }); $("#addRowContactPerson").click(function () { var validate_data_contact_person = checkIfContactPersonIncomplete(); if ( !validate_data_contact_person[0] && $("#contact-person-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data of contact person first" ); } else if (!validate_data_contact_person[1]) { sweetAlertSimple("error", "Oops...", "Contact person invalid email"); } else if (!validate_data_contact_person[2]) { sweetAlertSimple("error", "Oops...", "Contact person invalid mobile"); } else { addCustomerContactPerson(); } }); $("#contact-person-list").on("click", ".btnRemoveContactPerson", function () { $(this).closest("tr").remove(); }); //Date picker $("#mod-birth-date").datetimepicker({ format: "L", }); $("#mod-established-date").datetimepicker({ format: "L", }); $("[data-mask]").inputmask(); $("#modal-customer").on("hidden.bs.modal", function (e) { $(this) .find("input,textarea") .val("") .end() .find("select") .prop("selectedIndex", 0) .find("input[type=checkbox], input[type=radio]") .prop("checked", "") .end(); $(".modal-select2").val("").trigger("change"); }); $("#modal-customer").on("shown.bs.modal", function () { $("input:text:visible:first").focus(); }); $(document).on("wheel", "input[type=number]", function (e) { $(this).blur(); }); $("#mod-nature-of-business").select2({ // tags: true, placeholder: "Select Nature of Business", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/nature_of_business/nature_of_business.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6902545878701742", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-profession").select2({ tags: true, placeholder: "Select Profession", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/profession/profession.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8920139547181378", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-inquiry").select2({ placeholder: "Select Source of Inquiry", allowClear: true, }); $("#mod-dd-gender").select2({ placeholder: "Select Gender", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-marital-status").select2({ placeholder: "Select Marital Status", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-nationality").select2({ placeholder: "Select Nationality", allowClear: true, }); addRowInterest(); addRowAffiliations(); refreshModalReligion(); refreshModalCities(); initToolTip(); }); PK 8F�Z��Ե� �� dealer_cu_assign_form.jsnu �[��� var force_update = 0; var force_update_reason = ""; function removeextra() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9a-zA-Z]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function removeextranumonly() { var initVal = $(this).val(); outputVal = initVal.replace(/[^0-9()-]/g, ""); if (initVal != outputVal) { $(this).val(outputVal); } } function getCustomerAllModalData() { var /* Create an object. */ obj = {}, /* Create a variable that references the current object (default → obj). */ ref = obj; /* Iterate over every input. */ $("#modal-customer :input").each(function () { /* Cache the id of the input. */ var id = this.id; /* Check whether the nodetype attribute is set to 'parent'. */ if (this.getAttribute("nodetype") == "parent") { /* Set a new object to the property and set ref to refer to it. */ ref = obj[id] = {}; } else { /* Set the value of the input to the referred object. */ if (this.getAttribute("json-modal") == "true") { ref[id] = $(this).val(); } } }); /* Stringify the object and return it. */ return JSON.stringify(obj); } function sweetAlertSimple(icon, title, text) { // Swal.fire({ // icon: icon, // title: title, // text: text, // allowEnterKey: true // default value // }) toastr.remove(); switch (icon) { case "success": toastr.success(text); break; case "info": toastr.info(text); break; case "warning": toastr.warning(text); break; case "error": toastr.error(text); break; } } function getAllDataSourceTableData() { var $table = $("#data-source-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { var new_header = $(this).html().replace(/\s/g, "_").replace(/\./g, ""); header.push(new_header); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { if (header[i] == "Customer_No") { var key = header[i], value = $(this).find("input").val(); row[key] = value; } else { var key = header[i], value = $(this).find("select").val(); row[key] = value; } }); rows.push(row); }); return rows; } function checkIfDataSourceIncomplete() { rows = getAllDataSourceTableData(); var dataSourceJsonRow = rows; var hasMatch = true; for (var index = 0; index < dataSourceJsonRow.length; ++index) { var dataSourceJson = dataSourceJsonRow[index]; if ( // dataSourceJson.Customer_No == "" || dataSourceJson.DMS == "" || dataSourceJson.Company == "" || dataSourceJson.Dealer == "" ) { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function handleError(xhr, status, error) { //hide loader sweetAlertSimple("error", "Oops...", "Error has occurred, Try again..."); $("#proceed-button").attr("disabled", false); $(".customer-modal-overlay").hide(); force_update = 0; force_update_reason = ""; } function refreshModalCities() { $.ajax({ url: "api/city/city.php", type: "GET", dataType: "json", data: { apiKey: "5881641680981247", }, beforeSend: function () { $("#mod-dd-city-1").prop("disabled", true); $("#mod-dd-city-2").prop("disabled", true); }, success: function (result) { $("#mod-dd-city-1").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-2").select2({ data: result, placeholder: "Select City", allowClear: true, }); $("#mod-dd-city-1").prop("disabled", false); $("#mod-dd-city-2").prop("disabled", false); }, }); } function checkIfChildrenIncomplete() { rows = getAllChildrenTableData(); var childrenJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; for (var index = 0; index < childrenJsonRow.length; ++index) { var childrenJson = childrenJsonRow[index]; if ( childrenJson.Firstname == "" || childrenJson.Lastname == "" || childrenJson.Birthday == "" ) { hasMatch[0] = false; break; } if (!isEmpty(childrenJson.Mobile)) { if (childrenJson.Mobile.length < 10) { hasMatch[1] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllChildrenTableData() { var $table = $("#children-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function isEmail(email) { var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/; return regex.test(email); } function isEmpty(string) { var flag = false; try { if (string.trim() == "") { flag = true; } else if (string == null) { flag = true; } else if (typeof string === "undefined") { flag = true; } } catch (err) { // console.log(err); flag = true; } return flag; } function checkIfContactPersonIncomplete() { rows = getAllContactPersonTableData(); var contactPersonJsonRow = rows; var hasMatch = []; hasMatch[0] = true; hasMatch[1] = true; hasMatch[2] = true; for (var index = 0; index < contactPersonJsonRow.length; ++index) { var contactPersonJson = contactPersonJsonRow[index]; if ( contactPersonJson.Fullname == "" /* || contactPersonJson.Lastname == "" || contactPersonJson.Mobile == ""*/ ) { hasMatch[0] = false; break; } if (contactPersonJson.Email != "") { if (!isEmail(contactPersonJson.Email)) { hasMatch[1] = false; break; } } if (!isEmpty(contactPersonJson.Mobile)) { if (contactPersonJson.Mobile.length < 10) { hasMatch[2] = false; break; } } } // alert(hasMatch) return hasMatch; } function getAllContactPersonTableData() { var $table = $("#contact-person-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("input").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function addCustomerChildren() { var children_list = document.getElementById("children-list"); const children_list_base = document.querySelector( "#children-list-clone tbody tr" ); children_list.appendChild(children_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var ChildrenIdDateNow = uniqId(); var newChildrenFirstnameId = "children-firstname-" + ChildrenIdDateNow; var newChildrenLastnameId = "children-lastname-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "div-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "append-children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayId = "children-birthday-" + ChildrenIdDateNow; var newChildrenBirthdayDivId = "children-birthday-div-" + ChildrenIdDateNow; var newChildrenBirthdayAppendId = "children-birthday-append-" + ChildrenIdDateNow; var newChildrenMobileId = "children-mobile-append-" + ChildrenIdDateNow; var item = []; item[0] = newChildrenFirstnameId; item[1] = newChildrenLastnameId; item[2] = newChildrenBirthdayId; item[3] = newChildrenMobileId; $("#mod-children-firstname").attr("id", newChildrenFirstnameId); $("#mod-children-lastname").attr("id", newChildrenLastnameId); $("#mod-children-mobile").attr("id", newChildrenMobileId); $("#mod-children-birthdate") .attr("id", newChildrenBirthdayId) .data("target", "#" + newChildrenBirthdayDivId) .inputmask(); $("#mod-children-birthdate-append") .attr("id", newChildrenBirthdayAppendId) .data("target", "#" + newChildrenBirthdayDivId); $("#mod-children-birthdate-div") .attr("id", newChildrenBirthdayDivId) .datetimepicker({ format: "L", }); return item; } function addCustomerContactPerson() { var contact_person_list = document.getElementById("contact-person-list"); const contact_person_list_base = document.querySelector( "#contact-person-list-clone tbody tr" ); contact_person_list.appendChild(contact_person_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var contactPersonIdDateNow = uniqId(); var newContactPersonFullnameId = "contact-person-fullname-" + contactPersonIdDateNow; var newContactPersonFirstnameId = "contact-person-firstname-" + contactPersonIdDateNow; var newContactPersonLastnameId = "contact-person-lastname-" + contactPersonIdDateNow; var newContactPersonEmailId = "contact-person-email-" + contactPersonIdDateNow; var newContactPersonMobileId = "contact-person-mobile-" + contactPersonIdDateNow; var item = []; item[0] = newContactPersonFullnameId; item[1] = newContactPersonEmailId; item[2] = newContactPersonMobileId; $("#modal-contact-person-fullname").attr("id", newContactPersonFullnameId); $("#modal-contact-person-email").attr("id", newContactPersonEmailId); $("#modal-contact-person-mobile").attr("id", newContactPersonMobileId); return item; } function addRowInterest() { $("#addRow").click(function () { if ( !checkIfInterestIncomplete() && $("#interest-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the interest/hobbies details first" ); } else { addInterestItem(); } }); $("#interest-list").on("click", ".btnRemove", function () { $(this).closest("tr").remove(); }); } function getAllInterestTableData() { var $table = $("#interest-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html()); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfInterestIncomplete() { rows = getAllInterestTableData(); var interestJsonRow = rows; var hasMatch = true; for (var index = 0; index < interestJsonRow.length; ++index) { var interestJson = interestJsonRow[index]; if (interestJson.Category == "" || interestJson.Interest == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function addRowAffiliations() { $("#addRowAffiliations").click(function () { if ( !checkIfAffiliationsIncomplete() && $("#affiliations-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the affiliation details first" ); } else { addAffiliationsItem(); } }); $("#affiliations-list").on("click", ".btnRemoveAffiliations", function () { $(this).closest("tr").remove(); }); } function getAllAffiliationsTableData() { var $table = $("#affiliations-list-table"); (rows = []), (header = []); $table.find("thead th").each(function () { header.push($(this).html().replace(/\s/g, "_").replace(/\./g, "")); }); $table.find("tbody tr").each(function () { var row = {}; $(this) .find("td") .each(function (i) { var key = header[i], value = $(this).find("select").val(); row[key] = value; }); rows.push(row); }); // alert(JSON.stringify(rows)); // return JSON.stringify(rows); return rows; } function checkIfAffiliationsIncomplete() { rows = getAllAffiliationsTableData(); var jsonRow = rows; var hasMatch = true; for (var index = 0; index < jsonRow.length; ++index) { var json = jsonRow[index]; if (json.Category == "" || json.Affiliations == "") { hasMatch = false; break; } } // alert(hasMatch) return hasMatch; } function refreshModalReligion() { $.ajax({ url: "api/religion/religion.php", method: "POST", data: { apiKey: "2011315786548487", }, cache: false, beforeSend: function () {}, success: function (result) { var obj = jQuery.parseJSON(result); $("#mod-dd-religion").select2({ tags: true, placeholder: "Select Religion", allowClear: true, data: obj, }); }, }); } function resetCustomerModal() { $("#mod-dd-nationality").val("608").trigger("change"); $("#interest-list-table > tbody").empty(); $("#affiliations-list-table > tbody").empty(); $("#contact-person-list-table > tbody").empty(); $("#children-list-table > tbody").empty(); $("#data-source-list-table > tbody").empty(); $("#educational-bg-list-table > tbody").empty(); $("#car-clubs-list-table > tbody").empty(); $("#unit-association-list-table > tbody").empty(); $("#political-clubs-list-table > tbody").empty(); $("#network-marketing-list-table > tbody").empty(); $("#media-publications-list-table > tbody").empty(); $("#sme-groups-list-table > tbody").empty(); $("#fraternities-sororities-list-table > tbody").empty(); $("#facebook-groups-list-table > tbody").empty(); $("#celebrity-influencers-list-table > tbody").empty(); addCustomerModalTabSelectedTab(1); } function checkFieldsModal(isIndividual) { if (isIndividual) { $(".children-stepper").show(); $(".interest-stepper").show(); $(".interest-list").show(); $("#div-mod-firstname").show(); $("#div-mod-middlename").show(); $("#div-mod-lastname").show(); $("#div-mod-suffix").show(); $("#div-corporation-name").hide(); $("#mod-birthdate-label").text("Date of birth"); $("#div-mod-gender").show(); $("#div-mod-nationality").show(); $("#div-mod-occupation").show(); $("#div-mod-marital-status").show(); // $('#mod-contact-corporation-div').hide(); // $('#mod-contact-div').show(); $("#div-mod-spouse").show(); $("#div-mod-no-of-children").show(); $("#div-mod-business-company").show(); $("#div-mod-position").show(); $("#div-mod-religion").show(); $("#div-mod-profession").show(); $("#div-corporation-name").hide(); $("#div-mod-age-of-company").hide(); $("#educational_bg_div").show(); } else { $(".children-stepper").hide(); $(".interest-stepper").hide(); $(".interest-list").hide(); $("#div-mod-firstname").hide(); $("#div-mod-middlename").hide(); $("#div-mod-lastname").hide(); $("#div-mod-suffix").hide(); $("#div-corporation-name").show(); $("#mod-birthdate-label").text("Date Established"); $("#div-mod-gender").hide(); $("#div-mod-nationality").hide(); $("#div-mod-occupation").hide(); $("#div-mod-marital-status").hide(); // $('#mod-contact-corporation-div').show(); // $('#mod-contact-div').hide(); $("#div-mod-spouse").hide(); $("#div-mod-no-of-children").hide(); $("#div-mod-business-company").hide(); $("#div-mod-position").hide(); $("#div-mod-religion").hide(); $("#div-mod-profession").hide(); $("#div-mod-date-established").show(); $("#div-mod-age-of-company").show(); $("#educational_bg_div").hide(); } } function addCustomerModalTabSelectedTab(type) { $("#customer-modal-tab .nav-link").removeClass("active"); $("#customer-modal-tab-content .tab-pane").removeClass("show"); $("#customer-modal-tab-content .tab-pane").removeClass("active"); switch (type) { case 1: $("#customer-modal-tab-information").addClass("active"); $("#customer-modal-information").addClass("active"); $("#customer-modal-information").addClass("show"); break; case 2: $("#customer-modal-tab-contact").addClass("active"); $("#customer-modal-contact").addClass("active"); $("#customer-modal-contact").addClass("show"); break; case 3: $("#customer-modal-tab-children").addClass("active"); $("#customer-modal-children").addClass("active"); $("#customer-modal-children").addClass("show"); break; case 4: $("#customer-modal-tab-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("active"); $("#customer-modal-affiliations").addClass("show"); break; case 5: $("#customer-modal-tab-interest").addClass("active"); $("#customer-modal-interest").addClass("active"); $("#customer-modal-interest").addClass("show"); break; } } function uniqId() { return Math.round(new Date().getTime() + Math.random() * 100); } function checkIfEmpty(value, row, index) { if (value == "" || value == "-" || value == null) { return "<span style='color:red;'> (Not Provided) </span>"; } return value; } function getCookie(name) { var match = document.cookie.match(RegExp("(?:^|;\\s*)" + name + "=([^;]*)")); return match ? match[1] : null; } function imageFormatter(value, row, index) { return ( '<img width="50px" height="50px" class="user-image img-circle elevation-2" src="dist/img/thumbnail/' + value + '" />' ); } function initToolTip() { var bootstrapTooltip = $.fn.tooltip.noConflict(); $.fn.bstooltip = bootstrapTooltip; $(".tooltip-me").bstooltip(); } function tableMobileFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } return "<a href='tel:" + value + "'>" + value + "</a>"; } function tableNameFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } //ACTIVE LINK TRIGGER EDIT return "<a href='dealer-view?q=" + row.ref_num_header_link + "'>" + value + "</a>"; } function tableEmailFormatter(value, row, index) { if ((value != null && value.trim() == "") || value == "-") { return "<span style='color:red;'> (Not Provided) </span>"; } if (value == "-1") { return ""; } // return "<a href='mailto:" + value + "'>" + value + "</a>"; return value; } function addDataSourceItem() { var data_source = document.getElementById("data-source-list"); const data_source_base = document.querySelector( "#data-source-list-clone tbody tr" ); data_source.appendChild(data_source_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var dataSourceIdDateNow = uniqId(); var newDataSourceCustomerNoId = "data-source-customer-no-" + dataSourceIdDateNow; var newDataSourceDmsId = "data-source-dms-" + dataSourceIdDateNow; var newDataSourceCompanyId = "data-source-company-" + dataSourceIdDateNow; var newDataSourceDealerId = "data-source-dealer-" + dataSourceIdDateNow; var dataSourceItem = []; dataSourceItem[0] = newDataSourceCustomerNoId; dataSourceItem[1] = newDataSourceDmsId; dataSourceItem[2] = newDataSourceCompanyId; dataSourceItem[3] = newDataSourceDealerId; $("#input-modal-customer-no").attr("id", newDataSourceCustomerNoId); $("#" + newDataSourceCustomerNoId) .on("keyup", removeextra) .blur(removeextra); $("#" + newDataSourceCustomerNoId).on("keypress", function (e) { var regex = new RegExp("^[0-9a-zA-Z]+$"); var str = String.fromCharCode(!e.charCode ? e.which : e.charCode); if (regex.test(str)) { return true; } e.preventDefault(); return false; }); $("#select-modal-dms").attr("id", newDataSourceDmsId).select2({ placeholder: "Select DMS", allowClear: true, }); $("#select-modal-company") .attr("id", newDataSourceCompanyId) .select2({ placeholder: "Select Company", allowClear: true, language: { noResults: function () { return "Select DMS first"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/company/company.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term dms_id: $("#" + newDataSourceDmsId).val(), apiKey: "3568127986733141", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-preferred-moc").select2({ placeholder: "Select mode of contact", allowClear: true, tags: false, minimumResultsForSearch: -1, language: { noResults: function () { return "Select mode of contact"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/mode_of_contact/mode_of_contact.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "1557741601453763", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-business-company").select2({ placeholder: "Search Company by name, email and mobile", allowClear: true, language: { noResults: function () { return "Search Company by name, email and mobile"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/customer_update/customerv2_update.php", dataType: "json", delay: 250, data: function (data) { return { search: data.term, // search term apiKey: "3975247589935894", }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#select-modal-dealer") .attr("id", newDataSourceDealerId) .select2({ placeholder: "Select Dealer", allowClear: true, language: { noResults: function () { return "Search or enter dealer name"; }, }, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/dealer/dealer.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6209267133015033", company_id: $("#" + newDataSourceCompanyId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newDataSourceDmsId).on("change", function (event) { $("#" + newDataSourceCompanyId) .val("") .trigger("change"); }); $("#" + newDataSourceCompanyId).on("change", function (event) { $("#" + newDataSourceDealerId) .val("") .trigger("change"); }); return dataSourceItem; } function addInterestItem() { // CREATE ROW var interest_list = document.getElementById("interest-list"); const interest_list_base = document.querySelector( "#interest-list-clone tbody tr" ); var interestItem = []; interest_list.appendChild(interest_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var InterestIdDateNow = uniqId(); var newInterestCategoryId = "interest-category-" + InterestIdDateNow; var newInterestContentId = "interest-content-" + InterestIdDateNow; interestItem[0] = newInterestCategoryId; interestItem[1] = newInterestContentId; // alert(interestItem.pop(0)); // alert(interestItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category").attr("id", newInterestCategoryId).select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content") .attr("id", newInterestContentId) .select2({ tags: true, placeholder: "Select", allowClear: true, language: { noResults: function () { return "Search or enter interest"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter interest", ajax: { url: "api/interest_hobbies/interest_hobbies.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "5068581874181452", interestCategory: $("#" + newInterestCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#" + newInterestCategoryId).on("select2:select", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); $("#" + newInterestCategoryId).on("select2:unselecting", function (e) { $("#" + newInterestContentId) .val("") .trigger("change"); }); return interestItem; // CREATE ROW } function addAffiliationsItem() { // CREATE ROW var affiliations_list = document.getElementById("affiliations-list"); const affiliations_list_base = document.querySelector( "#affiliations-list-clone tbody tr" ); var affiliationsItem = []; affiliations_list.appendChild(affiliations_list_base.cloneNode(true)); // Generate a unique ID for the select> in the new row. var affiliationsIdDateNow = uniqId(); var newaffiliationsCategoryId = "affiliations-category-" + affiliationsIdDateNow; var newaffiliationsContentId = "affiliations-content-" + affiliationsIdDateNow; affiliationsItem[0] = newaffiliationsCategoryId; affiliationsItem[1] = newaffiliationsContentId; // alert(affiliationsItem.pop(0)); // alert(affiliationsItem.pop(1)); // Update the ID of the select> in the new row // (it should be the only one with an `id` of '#element'), // and initialize the Select2. $("#select-category-affiliations") .attr("id", newaffiliationsCategoryId) .select2({ placeholder: "Select Category", allowClear: true, }); $("#select-content-affiliations") .attr("id", newaffiliationsContentId) .select2({ tags: true, placeholder: "Search or enter affiliations", allowClear: true, language: { noResults: function () { return "Search or enter affiliations"; }, }, escapeMarkup: function (markup) { return markup; }, placeholder: "Search or enter affiliations", ajax: { url: "api/affiliations/affiliations.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8048636851659915", affiliationsCategory: $("#" + newaffiliationsCategoryId).val(), search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); // $('#' + newaffiliationsCategoryId).on('select2:select', function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); // $('#' + newaffiliationsCategoryId).on("select2:unselecting", function(e) { // $('#' + newaffiliationsContentId).val('').trigger('change') // }); return affiliationsItem; // CREATE ROW } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function () { $("#addRowDataSource").click(function () { if ( !checkIfDataSourceIncomplete() && $("#data-source-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data source details first" ); } else { addDataSourceItem(); } }); $("#data-source-list").on("click", ".btnRemoveDataSource", function () { if ($("#data-source-list-table tbody tr").length < 2) { sweetAlertSimple("error", "Oops...", "Need at least 1 data source"); } else { $(this).closest("tr").remove(); } }); $("#addRowChildren").click(function () { var validate_data_children_list = checkIfChildrenIncomplete(); if ( !validate_data_children_list[0] && $("#children-list-table tbody tr").length > 0 ) { sweetAlertSimple("error", "Oops...", "Complete the child details first"); } else if (!validate_data_children_list[1]) { sweetAlertSimple("error", "Oops...", "Children data invalid mobile"); } else { addCustomerChildren(); } }); $("#children-list").on("click", ".btnRemoveChildren", function () { $(this).closest("tr").remove(); }); $("#addRowContactPerson").click(function () { var validate_data_contact_person = checkIfContactPersonIncomplete(); if ( !validate_data_contact_person[0] && $("#contact-person-list-table tbody tr").length > 0 ) { sweetAlertSimple( "error", "Oops...", "Complete the data of contact person first" ); } else if (!validate_data_contact_person[1]) { sweetAlertSimple("error", "Oops...", "Contact person invalid email"); } else if (!validate_data_contact_person[2]) { sweetAlertSimple("error", "Oops...", "Contact person invalid mobile"); } else { addCustomerContactPerson(); } }); $("#contact-person-list").on("click", ".btnRemoveContactPerson", function () { $(this).closest("tr").remove(); }); //Date picker $("#mod-birth-date").datetimepicker({ format: "L", }); $("#mod-established-date").datetimepicker({ format: "L", }); $("[data-mask]").inputmask(); $("#modal-customer").on("hidden.bs.modal", function (e) { $(this) .find("input,textarea") .val("") .end() .find("select") .prop("selectedIndex", 0) .find("input[type=checkbox], input[type=radio]") .prop("checked", "") .end(); $(".modal-select2").val("").trigger("change"); }); $("#modal-customer").on("shown.bs.modal", function () { $("input:text:visible:first").focus(); }); $(document).on("wheel", "input[type=number]", function (e) { $(this).blur(); }); $("#mod-nature-of-business").select2({ // tags: true, placeholder: "Select Nature of Business", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/nature_of_business/nature_of_business.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "6902545878701742", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-profession").select2({ tags: true, placeholder: "Select Profession", allowClear: true, escapeMarkup: function (markup) { return markup; }, ajax: { url: "api/profession/profession.php", dataType: "json", delay: 250, data: function (data) { return { apiKey: "8920139547181378", search: data.term, // search term }; }, processResults: function (response) { return { results: response, }; }, cache: true, }, }); $("#mod-dd-inquiry").select2({ placeholder: "Select Source of Inquiry", allowClear: true, }); $("#mod-dd-gender").select2({ placeholder: "Select Gender", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-marital-status").select2({ placeholder: "Select Marital Status", allowClear: true, minimumResultsForSearch: -1, }); $("#mod-dd-nationality").select2({ placeholder: "Select Nationality", allowClear: true, }); addRowInterest(); addRowAffiliations(); refreshModalReligion(); refreshModalCities(); initToolTip(); }); PK 8F�ZFz��( �( dealer_assign.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return '';//'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return ''//'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var batch_no = ($("#batch").val() == '') ? '0' : $("#batch").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/dealer_customerv2_update.php", type: "POST", dataType: 'json', data: { batch: batch, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { // console.log('result total' +result); a=result.total_icu.replace(/\,/g,''); // 1125, but a string, so convert it to number total_avail_inactive=parseInt(a,10); $("#no_assign").attr({ "max" : total_avail_inactive, "min" : 1 }); $('#total_customer_count').text(result.total_icu); if(result.total_icu ==0) { $("#sl_company").attr('disabled', true); $("#btn-submit-manually").attr('disabled', true); } else { $("#sl_company").attr('disabled', false); $("#btn-submit-manually").attr('disabled', false); } // $('#new_customer_count').text(result.new_customer_count); // $('#updated_customer_count').text(result.updated_customer_count); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_dealer_assignment_update_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_customer_update_list.php', type: "POST", dataType: 'json', data: { search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_new').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('new').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#dms').select2({ // placeholder: "DMS Type", placeholder: "Batch No", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // // alert("click outside"); // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); function company() { $.ajax({ url: "api/customer_update/assign_dealer.php", type: "POST", dataType: 'json', data: { apiKey: 'mRLAZ8te7cnv', }, beforeSend: function() {}, success: function(result) { $("#sl_company").val(''); $.each(result, function(key, value) { $('#sl_company') .append($("<option></option>") .attr("value",value.id) .text(value.text)); }); } }); } company(); $("#sl_company").on('change', function(){ $("#sl_dealer").empty(); if($(this).val()!=''){ $("#sl_dealer").prop( "disabled", false ); $("#batchNo").prop("disabled",false); $("#sl_cu_city").prop('disabled',false); $("#sl_cu_city").attr('disabled',false); } else { $("#sl_dealer").prop( "disabled", true ); } $.ajax({ url: "api/customer_update/assign_dealer.php", type: "POST", dataType: 'json', data: { apiKey: 'f5AHTwg8MF9c', cid:$(this).val() }, beforeSend: function() {}, success: function(result) { $.each(result, function(key, value) { $('#sl_dealer') .append($("<option></option>") .attr("value",value.id) .text(value.text)); }); $("#sl_dealer").val(''); } }); }); // $("#sl_dealer").on('change', function(){ // $("#sl_user").empty(); // if($(this).val()!=''){ // $("#sl_user").prop( "disabled", false ); // } // else // { // $("#sl_user").prop( "disabled", true ); // } // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: 'L9T6kZfc8K4D', // cdi:$(this).val() // }, // beforeSend: function() {}, // success: function(result) { // $.each(result, function(key, value) { // $('#sl_user') // .append($("<option></option>") // .attr("value",value.id) // .text(value.text)); // }); // $("#sl_user").val(''); // } // }); // }); $("#sl_dealer").on('change', function(){ $("#no_assign").val(''); if($(this).val()!=''){ $("#no_assign").prop( "disabled", false ); } else { $("#no_assign").prop( "disabled", true ); } }); function autoAssign(apy) { $("#spinner-loader").show(); $('.fieldset').prop('disabled', true) $(":button").prop('disabled',true); $("#assign_to_dealers").hide(); $("#spinner-loader").show(); $.ajax({ url: "api/customer_update/assign_dealer.php",//"api/customer_update/customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: apy, // cdi:$(this).val() }, // beforeSend: function() {}, // beforeSend: function(xhr) { // // Show loader before the request starts // $("#spinner-loader").show(); // $('.fieldset').prop('disabled', true); // $(":button").prop('disabled', true); // $("#assign_to_dealers").hide(); // // Track progress // // Check if xhr.upload is defined before adding the event listener // if (xhr.upload) { // xhr.upload.addEventListener("progress", function(evt) { // if (evt.lengthComputable) { // var percentComplete = (evt.loaded / evt.total) * 100; // console.log(percentComplete + "%"); // // Update the progress bar or display the percentage as needed // } // }, false); // } // }, complete: function(){ $("#spinner-loader").hide(); $('.fieldset').prop('disabled', false) $(":button").prop('disabled',false); $("#assign_to_dealers").show(); }, success: function(result) { if(result.status==0){ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } if(result.status==1){ Swal.fire({ icon: 'success', title: 'Success!', text: result.no_assign+' '+result.msg+' '+result.no_of_dealers+' '+result.dealer, allowEnterKey: true // default value }); location.reload(); } } }); } function resetAssign(apy) { Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { $("#spinner-loader").show(); $('.fieldset').prop('disabled', true) $(":button").prop('disabled',true); $("#reset-assignment").hide(); $("#spinner-loader-purple").show(); $.ajax({ url: "api/customer_update/assign_dealer.php",//"api/customer_update/customerv2_update.php", type: "POST", dataType: 'json', data: { apiKey: apy, // cdi:$(this).val() }, // beforeSend: function() {}, // beforeSend: function(xhr) { // }, complete: function(){ $("#spinner-loader-purple").hide(); $('.fieldset').prop('disabled', false) $(":button").prop('disabled',false); $("#reset-assignment").show(); }, success: function(result) { if(result.status==0){ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } if(result.status==1){ Swal.fire({ icon: 'success', title: 'Success!', text: result.no_assign+' '+result.msg+' '+result.no_of_dealers+' '+result.dealer, allowEnterKey: true // default value }); location.reload(); } } }); } }); } // $(document).on('change', '.usr-id', function() { // let hdr = $(this).closest('tr').find('.hdr').val(); // let did = $(this).closest('tr').find('.did').val(); // $.ajax({ // url: "api/customer_update/assign_dealer.php", // type: "POST", // dataType: 'json', // data: { // apiKey: $("#ausr-py").val(), // uid:$(this).val(), // hdr:hdr, // did:did, // }, // success: function(result) { // if(result.status==1) // { // Swal.fire({ // icon: 'success', // title: 'Success!', // text: result.msg, // allowEnterKey: true // default value // }); // setTimeout(()=>{ // // location.reload(); // },3000); // } // if(result.status==0){ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: result.msg, // allowEnterKey: true // default value // }); // } // } // }); // }); function relodMdl() { location.reload(); } function loadDealers(apy){ $.ajax({ url: 'api/customer_update/assign_dealer.php', method: 'POST', data: {apiKey:apy }, success: function(response) { $('#table_dlr tbody').empty(); // Parse JSON response var dealers = JSON.parse(response); // Loop through each dealer object and append to the table $.each(dealers, function(index, dealer) { console.log(dealer); var row = $("<tr>"); row.append($("<td>").text(index+1)); row.append($("<td>").text(dealer.text)); row.append($("<td>").html("<input type='checkbox' class='chk-active-dlr' "+dealer.check+" value='" + dealer.id + "'/>")); row.append($("<td>").html("")); $('#table_dlr tbody').append(row); }); $('#table_dlr').DataTable({ // "scrollY": "300px", // Set fixed height with scrolling // "lengthMenu": false,//remove select result "paging": true, // Enable pagination "searching": true, // Enable search bar "pagingType": "simple_numbers", // Use buttons for pagination "language": { "paginate": { "previous": "<", "next": ">" } } }); }, error: function(xhr, status, error) { console.error(error); // Log any errors } }); } //select ALL CITY $("#select-all-btn-cities").on('click', function(){ $('#sl_cu_city option').prop('selected', true); $('#sl_cu_city').trigger('change'); // Select all options }); //clear all selected cities $("#clear-all-btn-cities").on('click', function(){ $('#sl_cu_city option').prop('selected', false); $('#sl_cu_city').trigger('change'); // Trigger change event if necessary }); $("#btn-submit-manually").on('click', function(e) { var selectCities = $("#sl_cu_city"); if(selectCities && selectCities.find("option:selected").length === 0){ // console.log('city is empty'); Swal.fire({ icon: 'warning', title: 'Oops!', text: " DB source city field is required.", allowEnterKey: true // default value }); return; } $(this).prop('disabled',true); e.preventDefault(); $.ajax({ url: "api/customer_update/assign_dealer.php", type: "POST", dataType: 'json', data: { apiKey: $("#apiy").val(), cty : selectCities.val(), btno:$("#batchNo").val(), cm: $("#sl_company").val(), dlr: $("#sl_dealer").val(), usr: $("#sl_user").val(), nos: $("#no_assign").val() }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: result.nos+' '+result.msg+' '+result.dealer, allowEnterKey: true // default value }); setTimeout(()=>{ location.reload(); },1300); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } $("#btn-submit-manually").prop('disabled',false); } }); }); $('#table_dlr').on('click', '.chk-active-dlr', function() { let dlr_id=[]; let active =($(this).is(':checked') ? 1 : 0); let data ={'did':$(this).val(),'active':active}; dlr_id.push(data); }); function chkAll() { let active = ($("#chk_all").is(':checked')) ? 0 : 1; // Determine active status dlr_id = []; // Clear the array // Iterate over all pages of DataTables $('#table_dlr').DataTable().rows().every(function(rowIdx, tableLoop, rowLoop) { // Get the data for each row let data = rowIdx;//this.data(); // Find the checkbox within the row let checkbox = $(this.node()).find('.chk-active-dlr'); // Set the checked state for each checkbox checkbox.prop('checked', active); // Push each checkbox's data into the dlr_id array dlr_id.push({'did': data, 'active': active}); }); console.log(dlr_id); } function exl_dlr() { let dlr_id= []; let active =1; $('#table_dlr').DataTable().rows().every(function(rowIdx, tableLoop, rowLoop) { // Get the data for each row (assuming you need this) let rowData = this.data(); // Find the checkbox within the row let checkbox = $(this.node()).find('.chk-active-dlr'); // Get the value of the checkbox let value = checkbox.val(); // Check if the checkbox is checked let active = (checkbox.is(':checked')) ? 0 : 1; // Push each checkbox's data into the dlr_id array dlr_id.push({'did': value, 'active': active}); }); $.ajax({ url: "api/customer_update/assign_dealer.php", type: 'POST', dataType: 'json', // data: {apiKey:excl_py,attr:active,did:$(this).val()}, data: {apiKey:excl_py,attr:dlr_id}, success: function(response) { if(response.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: response.msg, allowEnterKey: true // default value }); setTimeout(()=>{ Swal.close() ; // setTimeout(function () { // Swal.close() // }, 2000) },3000); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: response.msg, allowEnterKey: true // default value }); } }, error: function(error) { console.error(error); // Log any errors } }); } // } $("#assign_to_dealers").hide(); $("#fieldset-assign").hide(); function swichAssignment() { $('#toggleForms').change(function() { var label = $(this).prop('checked') ? 'Auto' : 'Manual'; $(this).siblings('.custom-control-label').text(label + ''); $(this).siblings('.fieldset-form').text(label + ''); if(label ==='Auto') { $("#assign_to_dealers").show(); $("#fieldset-assign").hide(); } if(label ==='Manual') { $("#assign_to_dealers").hide(); $("#fieldset-assign").show(); } }); } $(document).ready(function(){ $(document).on('click', '.btn-dealer-users', function() { // var didUsersValue = $(this).siblings('.modal-content').find('.did_users').val(); let dealer_id = $(this).attr("data-id"); let dealer_hdr = $(this).attr("data-hdr"); console.log(dealer_id+' '+dealer_hdr); $.ajax({ url: "api/customer_update/assign_dealer.php", type: 'POST', dataType: 'json', // data: {apiKey:excl_py,attr:active,did:$(this).val()}, data: {apiKey:apy,hdr: dealer_hdr,dealer_id : dealer_id}, success: function(response) { var isChecked =''; const userID=[]; const userNoDB=[]; $.each(response.users_in_cu_assigned,function(i,user_id){ userID.push(user_id); userNoDB.push(user_id['total_assigned']); }); console.log(userID); delete response.users_in_cu_assigned; delete response.user_total_assigned_db; $('.modal-body-user').empty(); $('.div-user').empty(); $(this).closest('.modal').find(".dealer_hdrs").empty(); $(this).closest('.modal').find(".daeler_ids").empty(); $(this).closest('.modal-body-user').html(''); // if($.isEmptyObject(response)){ // alert('empty'); // } // console.log(userNoDB); // console.log(userID);return; if(!$.isEmptyObject(response)){ $(".btn-save-users").prop('disabled',false); var divRowDealerInfo = $('<div></div>').addClass('row div-label').css('padding-top','1rem').css('padding-bottom','1rem').css('margin-bottom','10px'); var divRowLable = $('<div></div>').addClass('row div-label').css('padding-top','1rem').css('padding-bottom','1rem').css('margin-bottom','10px'); var actionLabel = $('<div></div>').addClass('col-md-1 ').text('Action').css('font-weight','Bold').css('font-size','15px'); var no_of_db_label = $('<div></div>').addClass('col-md-2 nodColumn').text('No of Database').css('font-weight','Bold').css('font-size','15px'); var gmsm_label= $('<div></div>').addClass('col-md-9').text("GM/SM").css('font-weight','Bold').css('font-size','15px').css('padding-left','1rem'); divRowLable.append(actionLabel,no_of_db_label,gmsm_label); $('.modal-body-user').append(divRowLable); $.each(response, function(e, v) { let currentAssignedDB = ''; let isChecked = false; // Initialize isChecked to false outside the loop // Check each element in userID for matching employee_id for (let i = 0; i < userID.length; i++) { if (userID[i] && typeof userID[i] === 'object' && userID[i]['user_id'].includes(`${v.employee_id}`)) { isChecked = true; currentAssignedDB = userID[i]['total_assigned']; console.log('true ' + userID[i]['user_id'] + ' ' + currentAssignedDB); break; // Exit the inner loop after finding a match } } // Create DOM elements based on the isChecked value var divRow = $('<div></div>').addClass('row div-user'); var checkColumn = $('<div></div>').addClass('col-md-1 '); var nodColumn = $('<div></div>').addClass('col-md-2 nodColumn'); var labelColumn = $('<div></div>').addClass('col-md-9'); var label = $('<label></label>').addClass('lbl-forms form-control').attr('for', 'employee').text(v.employee_name +' - '+v.position); if (isChecked) { var inputCheck = $('<input>').addClass('userID').attr({ 'name': 'userID[]', 'id': 'userID', 'type': 'checkbox','disabled':'disabled'}).val(v.employee_id).prop('checked', isChecked); var inputNoOfDb = $('<span>').attr({'name':'dealer_no_db','placeholder':'Enter no of DB','id':'dealer_no_db','class':'badge'}).text(currentAssignedDB).css('width','110px').css('background-color','#f9ce69').css('margin-top','10px'); } else { var inputCheck = $('<input>').addClass('userID').attr({ 'name': 'userID[]', 'id': 'userID', 'type': 'checkbox','disabled':'disabled'}).val(v.employee_id).prop('checked', isChecked).css('opacity','0.2'); var inputNoOfDb = $('<input>').attr({'name':'dealer_no_db','placeholder':'Enter no of DB','id':'dealer_no_db','required':'required','class':'form-control dealer_no_db','type':'number'}).val(currentAssignedDB).css('width','110px'); } let inputHdr = $('<input>').attr({'name':'dealer_hrd','id':'dealer_hrd','class':'form-control-sm dealer_hdrs','type':'hidden'}).val(dealer_hdr); let inputDid = $('<input>').attr({'name':'dealer_id','id':'dealer_id','class':'form-control-sm dealer_ids','type':'hidden'}).val(dealer_id); inputCheck.css('margin-top', '13px'); // Adjust this value to center the checkbox vertically label.css('margin-left', '-10px'); // Move the label element to the left by 10 pixels label.css('font-size', '16px'); label.css('border', 'none'); label.css('font-style','Italic'); nodColumn.append(inputNoOfDb); checkColumn.append(inputCheck); labelColumn.append(label); divRow.append(checkColumn,nodColumn, labelColumn); $('.modal-body-user').append(divRow,inputHdr,inputDid); }); } else { $(".btn-save-users").prop('disabled',true); $('#UserModal').modal('hide'); var SpanWarning = $('<span></span>').addClass('col-md-12 badge badge-warning').text("No users are available in this dealer."); $('.modal-body-user').append(SpanWarning); // Swal.fire({ // icon: 'warning', // title: 'Warning!', // text: "There is no avilable user to assign", // // allowEnterKey: true // default value // }); } }, error: function(error) { console.error(error); // Log any errors } }); }); // let uidarr = []; // $(document).on('click', '.userID', function() { // let currnetValue = $(this).val(); // if($(this).is(":checked")){ // uidarr= uidarr.concat(currnetValue); // $(this).closest('.modal').find('.nodColumn').show(); // $(this).closest('.modal').find('.nodColumn').focus(); // $(this).closest('.modal').find('.dealer_no_db').attr('required', true); // } // else // { // uidarr = uidarr.filter(element => element !== currnetValue); // $(this).closest('.modal').find('.nodColumn').hide(); // $(this).closest('.modal').find('.dealer_no_db').attr('required', false); // } // var hdrValue = $(this).closest('.modal').find('.dealer_hdrs').val(); // var didUsersValue = $(this).closest('.modal').find('.dealer_ids').val(); // //SALES MANAGER // $('.btn-save-users').off('click').on('click', function() { // var didUsersNoDB = $(this).closest('.modal').find('.dealer_no_db').val(); // if(isNaN(didUsersNoDB) || didUsersNoDB.trim() === ''){ // Swal.fire({ // icon: 'warning', // title: 'Oops!', // text: 'No of DB field is required', // allowEnterKey: true // default value // }); // } // else{ // var didUsersNoDB = $(this).closest('.modal').find('.dealer_no_db').val(); // Swal.fire({ // title: 'Are you sure?', // text: "You are about to execute this command. Do you want to proceed?", // icon: 'warning', // showCancelButton: true, // confirmButtonColor: '#3085d6', // cancelButtonColor: '#d33', // confirmButtonText: 'Yes, execute it!' // }).then((result) => { // if (result.isConfirmed) { // assignUsers([hdrValue, didUsersValue, uidarr, didUsersNoDB]); // } // }); // } // }); // }); $(document).on('keyup', '.dealer_no_db', function() { let currentCHK = $(this).closest('.div-user').find('.userID'); if ($(this).val() > 0) { currentCHK.prop('disabled', false); currentCHK.css({ 'opacity': '100', 'border': '2px solid black' }); currentCHK.prop('checked', false); // Uncheck the nearby checkbox } else { currentCHK.prop('disabled', true); currentCHK.prop('checked', false); // Uncheck the nearby checkbox currentCHK.css('opacity', '0.2'); } }); let userData = []; // Define userData array to store user data $(document).on('click', '.userID', function() { userData = []; let container = $(this).closest('.modal-body-user'); let currnetValue = $(this).val(); let no_of_db = 0; // Default value let hdr_value = container.find('.dealer_hdrs').val(); let dealer_value = container.find('.dealer_ids').val(); if ($(this).is(":checked")) { // Find the no_of_db input relative to the checkbox that was checked no_of_db = $(this).closest('.div-user').find('.dealer_no_db').val(); // Add user data to userData array if checkbox is checked and no_of_db is filled userData.push([currnetValue, no_of_db, hdr_value, dealer_value]); // $(this).closest('.div-user').find('.nodColumn').show(); $(this).closest('.div-user').find('.dealer_no_db').attr('required', true); } else { // Remove user data from userData array if checkbox is unchecked userData = userData.filter(user => user[0] !== currnetValue); // $(this).closest('.div-user').find('.nodColumn').hide(); $(this).closest('.div-user').find('.dealer_no_db').attr('required', false); } // console.log(userData); }); $(document).on('click', '.btn-save-users', function() { if(userData.length ===0) { Swal.fire({ icon: 'warning', title: 'Oops!', text: 'Please tick the box if you want to assign a user.', allowEnterKey: true // default value }); return; } let noDBEmpty = false; $.each(userData, function(e, v) { // console.log(v[1]) if(isNaN(v[1]) || v[1].trim() == '') { noDBEmpty = true; // Set flag to true if empty no_of_db is found return false; } }); if (noDBEmpty) { Swal.fire({ icon: 'warning', title: 'Oops!', text: 'No of DB field is required and it must be whole number.', allowEnterKey: true // default value }); $(".userID").prop('checked', false); return; // Exit the function if any empty no_of_db is found } // console.log(userData);return; Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { // console.log(hdrValue);console.log(didUsersValue); console.log(uidarr);console.log(didUsersNoDB);return; // assignUsers([hdrValue, didUsersValue, uidarr, didUsersNoDB]); assignUsers(userData); } }); }); function assignUsers(userInfo) { $.ajax({ url: "api/customer_update/assign_dealer.php", type: "POST", dataType: 'json', data: { apiKey: $("#ausr-py").val(), user_data:userInfo }, success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: result.msg, allowEnterKey: true // default value }); // location.reload(); setTimeout(()=>{ location.reload(); },2500); } if(result.status==0){ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } } }); } $("#sl_cu_city").on('change', function(){ $("#sl_company").prop('disabled',true); if($(this).val() != '') { $("#sl_company").prop('disabled',false); $("#sl_company").attr('disabled', false); } }); function load_city(){ $.ajax({ url: "api/customer_update/assign_dealer.php", type: "POST", dataType: 'json', data: { apiKey: 'L9T6kZfc8K4D', }, // beforeSend: function() {}, success: function(result) { $("#sl_cu_city").prop( "disabled", false ); // $("#sl_user").empty(); $.each(result, function(key, value) { var option = $("<option></option>") .attr("value", value.id) .text(value.text); $('#sl_cu_city').append(option); }); } }); } load_city(); const goBack = () => { window.history.back(); } }); PK 8F�Z��vժ ժ customer_user_assigned.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return 'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ url: "api/customer_update/customer_dealer_user_assigned.php", // url: "api/customer_update/dealer_view_assigned_cu.php", type: "POST", dataType: 'json', data: { ref_num_header: url_param, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month : filter_month, filter_year : filter_year, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { // console.log($result); $('#total_customer_count').text(result.total_icu_assigned); $('#pending_customer_count').text(result.pending_customer_count); $('#updated_customer_count').text(result.updated_customer_count); $('#active_customer_count').text(result.total_is_active); $('#inactive_customer_count').text(result.total_is_inactive); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_customer_user_assigned_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_customer_user_assigned_list.php', type: "POST", dataType: 'json', data: { ref_num_header:url_param, search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").hide();//show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { ref_num_header: url_param, search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month : filter_month, filter_year : filter_year, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-month').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-year').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_pending').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('pending').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_added').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('added').trigger('change'); }); $('#customer_action_active').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('active').trigger('change'); }); $('#customer_action_inactive').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('inactive').trigger('change'); }); $('#dms').select2({ placeholder: "DMS Type", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter document.getElementById("dropdown-filter").addEventListener('click', function(event) { // alert("click outside"); event.stopPropagation(); }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); $(document).on('change', ".is_active", function() { if ($(this).val() =='0') { Swal.fire({ icon: 'warning', title: 'Oops!', text: "Status field is required.", allowEnterKey: true // default value }); return false; // Prevent further execution if validation fails } Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { let st = $(this).val();//($(this).is(':checked') ? 1 : 0); $.ajax({ url: "api/customer_update/dealer_view_assigned_cu.php", type: "POST", dataType: 'json', data: { apiKey: setpy,val: $(this).attr("data-id"),attr:st },success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: result.msg, allowEnterKey: true // default value }); // location.reload(); setTimeout(()=>{ Swal.close() ; location.reload(); },2000); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } } }); } }); }); const goBack = () => { window.history.back(); } PK 8F�Z��Py�� �� dealer_view_cu.jsnu �[��� var new_customer_is_individual = false; var shown = false; var count_customer_summary = null; var customer_grid = null; var onShowFiltersDialog = function() { if (getCookie("customer_toggle") == null || parseInt($.cookie("customer_toggle")) == 0) { var $table = $('#customer-table'); $table.bootstrapTable('destroy'); initGrid() $.cookie("customer_toggle", 1); } else { // initList() $.cookie("customer_toggle", 0); } refreshTableCustomer() } function buttonsFunction() { return { grid_refresh: { 'icon': 'fa fa-sync', 'event': 'refreshTableCustomer', 'attributes': { 'title': 'Refresh', 'data-test': 'test123' } }, grid_toggle_on: { 'icon': 'fa fa-toggle-on', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle List View', 'data-test': 'test123' } }, grid_toggle_off: { 'icon': 'fa fa-toggle-off', 'event': 'onShowFiltersDialog', 'attributes': { 'title': 'Toggle Grid View', 'data-test': 'test123' } } } } function initGrid() { var $table = $('#customer-table'); // $table.bootstrapTable('destroy'); $table.bootstrapTable({ formatSearch: function() { return 'Search Customer' }, }); } function initList() { var $table = $('#customer-table') $table.bootstrapTable('destroy') $table.bootstrapTable({ sidePagination: 'server', formatSearch: function() { return 'Search Customer' }, onSearch: function(text) { $table.addClass('loading'); }, onLoadSuccess: function() { $table.removeClass('loading'); } }); } function customSearch(data, text) { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { refreshTableCustomer(); } return data.filter(function(row) { return row.name.toLowerCase().replace(/\s/g, "").indexOf(text.toLowerCase().replace(/\s/g, "")) > -1 }) } function customerCountSummary() { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); if(count_customer_summary != null){ count_customer_summary.abort(); } count_customer_summary = $.ajax({ // url: "api/customer/customerv2_update.php", url: "api/customer_update/dealer_view_assigned_cu.php", type: "POST", dataType: 'json', data: { ref_num_header: ref_num_header, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month : filter_month, filter_year : filter_year, apiKey: '8666264351338448', my_records : my_records }, beforeSend: function() {}, success: function(result) { // console.log($result); $('#total_customer_count').text(result.total_icu_assigned); $('#pending_customer_count').text(result.pending_customer_count); $('#updated_customer_count').text(result.updated_customer_count); $('#active_customer_count').text(result.total_is_active); $('#inactive_customer_count').text(result.total_is_inactive); // $('#new_today_customer_count').text(result.new_today_customer_count); } }); } function refreshTableCustomer() { if (getCookie("customer_toggle") != null && $.cookie("customer_toggle") == 1) { initGrid() getCustomerGrid(0, 9); showGrid(); } else { initList() var $table = $('#customer-table') // $table.bootstrapTable('destroy') $(function() { $table.bootstrapTable('refresh', { url: 'app/table/bt_dealer_view_customer_update_list.php' }); }) showList(); } customerCountSummary(); } function gotoOffsetCustomer(n) { // alert(n) // $.cookie("customer_list_offset",n); getCustomerGrid(n, 9); } function getCustomerGrid(offset, limit) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var search = $(".search-input").val(); var my_records = $('#my_record_filter').is(":checked"); if(customer_grid != null){ customer_grid.abort(); } customer_grid = $.ajax({ url: 'app/table/bt_dealer_view_customer_update_list.php', type: "POST", dataType: 'json', data: { ref_num_header:ref_num_header, search: search, grid: 1, offset: offset, limit: limit, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, customer_actions: customer_actions, my_records : my_records }, beforeSend: function() { $('#loader-main').show(); }, success: function(result) { // result.total $('#customer-grid-data').html(''); $('#customer-grid-data').append(result.customer_list); $('#customer-grid-data-paging').html(''); // if(result.total <= 0){ // $('#customer-grid-data-paging').append(result.customer_list_paging); // } // if(result.grid_offset > 6){ $('#customer-grid-data-paging').append(result.customer_list_paging); // } $('#loader-main').hide(); } }); } function showGrid() { $("#customer-grid").show(); $("#grid-card").show(); $('#customer-grid-data-paging').show(); $("button[name='grid_toggle_on']").hide();//show(); $("#customer-table").hide(); $(".fixed-table-pagination").hide(); $("button[name='grid_toggle_off']").hide(); } function showList() { $("#customer-table").show(); $("#grid-card").hide(); $(".fixed-table-pagination").show(); $("button[name='grid_toggle_off']").hide();//show(); $("#customer-grid").hide(); $('#customer-grid-data-paging').hide(); $("button[name='grid_toggle_on']").hide(); } function queryParams(params) { var dms = ($("#dms").val() == '') ? '0' : $("#dms").val(); var company = ($("#company-filter").val() == '') ? '0' : $("#company-filter").val(); var gender = ($("#gender").val() == '') ? 'all' : $("#gender").val(); var type = ($("#type").val() == '') ? '0' : $("#type").val(); var filter_age = ($("#filter-age").val() == '') ? '0' : $("#filter-age").val(); var filter_data = ($("#filter-data").val() == '') ? '0' : $("#filter-data").val(); var filter_month = ($("#filter-month").val() == '') ? '0' : $("#filter-month").val(); var filter_year = ($("#filter-year").val() == '') ? '0' : $("#filter-year").val(); var customer_actions = ($("#customer-actions").val() == '') ? '0' : $("#customer-actions").val(); var my_records = $('#my_record_filter').is(":checked"); return { ref_num_header: ref_num_header, search: params.search, offset: params.offset, limit: params.limit, sort: params.sort, order: params.order, dms: dms, company: company, type: type, gender: gender, filter_age: filter_age, filter_data: filter_data, filter_month : filter_month, filter_year : filter_year, customer_actions: customer_actions, my_records : my_records }; } function customerModal(isIndividual) { new_customer_is_individual = isIndividual; $('#proceed-button').text("Add Customer"); $('.customer-modal-overlay').hide(); if (isIndividual) { $('#modal-title').text("New Customera (Individual)"); checkFieldsModal(true); } else { $('#modal-title').text("New Customerb (Corporation)"); checkFieldsModal(false); } resetCustomerModal(); $("#addRowDataSource").click(); } function customerInfo(id) { $.cookie("customer_selected_tab", 'custom-tabs-three-home-tab'); // window.location.href = "customer_view.php?q=" + id; } function addFilterListener(){ $('#dms').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#company-filter').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#gender').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#type').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-data').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-age').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-month').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); $('#filter-year').off('change.mychange').on('change.mychange', function() { $('#customer-actions').off('change.mychange'); $('#customer-actions').val('').trigger('change') addFilterListenerCustomerAction(); refreshTableCustomer(); }); addFilterListenerCustomerAction(); } function addFilterListenerCustomerAction(){ $('#customer-actions').off('change.mychange').on('change.mychange', function() { refreshTableCustomer(); }); } ///////////////////////////////////////////////////////////////////////////////////////////////////// $(document).ready(function() { // if (getCookie("customer_toggle") != null && parseInt($.cookie("customer_toggle")) == 1) { // initGrid() // } else { // initList() // } refreshTableCustomer() addFilterListener(); var $table = $('#customer-table'); $('#customer_action_all').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('all').trigger('change'); }); $('#customer_action_pending').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('pending').trigger('change'); }); $('#customer_action_updated').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('updated').trigger('change'); }); $('#customer_action_active').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('active').trigger('change'); }); $('#customer_action_inactive').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('inactive').trigger('change'); }); $('#customer_action_pending').on('click', function(event) { $table.addClass('loading'); $('#customer-actions').val('pending').trigger('change'); }); $('#dms').select2({ placeholder: "Batch no", allowClear: true }) $('#company-filter').select2({ placeholder: "Company", allowClear: true }) $('#gender').select2({ placeholder: "Gender", allowClear: true }) $('#type').select2({ placeholder: "Customer Type", allowClear: true }) $('#filter-age').select2({ placeholder: "Age", allowClear: true }) $('#filter-data').select2({ placeholder: "Data Type", allowClear: true }) $('#filter-month').select2({ placeholder: "Month", allowClear: true }) $('#filter-year').select2({ placeholder: "Year", allowClear: true }) $('#customer-actions').select2({ placeholder: "Customer Actions", allowClear: true }) $( "#my_record_filter").on( "click", function() { refreshTableCustomer(); }); $('#customer-table').on('click-cell.bs.table', function(field, value, row, $el) { // alert(value) if (value == 'email_1' || value == 'mobile_phone_1') { return; } customerInfo($el.id); }); //for click bnalloon not hiding -> filter // document.getElementById("dropdown-filter").addEventListener('click', function(event) { // // alert("click outside"); // event.stopPropagation(); // }); $('#new-customer').on("click", function() { shown ? $(this).hideBalloon() : $(this).showBalloon(); shown = !shown; }).showBalloon({ position: 'right', html: true, css: { color: 'black' }, contents: ` <div class="row"> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(true)" id="new-individual-customer" class="btn btn-primary btn-sm" value="Individual" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-6 p-1"> <input style="width: 90px !important;" type="button" onclick="customerModal(false)" id="new-corporate-customer" class="btn btn-primary btn-sm" value="Corporation" data-toggle="modal" data-target="#modal-customer"></input> </div> <div class="col-sm-4 p-1" hidden> <input style="width: 90px !important;" type="button" id="new-import-customer" class="btn btn-primary btn-sm" value="Import"></input> </div> </div> ` }); $('#new-customer').hideBalloon(); $(document).mouseup(function(e) { var container = $("#new-customer"); // if the target of the click isn't the container nor a descendant of the container if (!container.is(e.target) && container.has(e.target).length === 0) { container.hideBalloon(); shown = false; } }); $('#btnCustomerListNoFilter').click(function() { $('#dms').off('change.mychange'); $('#company-filter').off('change.mychange'); $('#gender').off('change.mychange'); $('#type').off('change.mychange'); $('#filter-age').off('change.mychange'); $('#filter-data').off('change.mychange'); $('#filter-month').off('change.mychange'); $('#filter-year').off('change.mychange'); $('#customer-actions').off('change.mychange'); $('#dms').val('').trigger('change') $('#company-filter').val('').trigger('change') $('#gender').val('').trigger('change') $('#type').val('').trigger('change') $('#filter-age').val('').trigger('change') $('#filter-data').val('').trigger('change') $('#filter-month').val('').trigger('change') $('#filter-year').val('').trigger('change') $('#customer-actions').val('').trigger('change') $('#my_record_filter').prop('checked', false); addFilterListener(); refreshTableCustomer(); }) $('#proceed-button').on("click", function() { // alert('fire'); return; if (new_customer_is_individual) { if (isEmpty($('#mod-firstname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-firstname').focus(); sweetAlertSimple('error', 'Oops...', 'Firstname can\'t be left blank') return; } if (isEmpty($('#mod-lastname').val())) { addCustomerModalTabSelectedTab(1); $('#mod-lastname').focus(); sweetAlertSimple('error', 'Oops...', 'Lastname can\'t be left blank') return; } if (!isEmpty($('#mod-birthdate').val())) { cust_dob = new Date($('#mod-birthdate').val()); var cust_today = new Date(); var cust_age = Math.floor((cust_today-cust_dob) / (365.25 * 24 * 60 * 60 * 1000)); // alert(cust_age+' years old'); if(parseInt(cust_age) < 17 ){ addCustomerModalTabSelectedTab(1); $('#mod-birthdate').focus(); sweetAlertSimple('error', 'Oops...', 'Age must be 17 and above.') return; } } } else { if (isEmpty($('#mod-corporation-name').val())) { addCustomerModalTabSelectedTab(1); $('#mod-corporation-name').focus(); sweetAlertSimple('error', 'Oops...', 'Corporation name can\'t be left blank') return; } } if (!checkIfDataSourceIncomplete() && $('#data-source-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data source details first'); return; } if (new_customer_is_individual) { if (isEmpty($('#mod-contact').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number is required'); return; } if ($('#mod-contact').val().length < 10 || !$('#mod-contact').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else { if (isEmpty($('#mod-contact').val()) && isEmpty($('#mod-landline').val())) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Mobile number or landline is required'); return; } if (!isEmpty($('#mod-contact').val())) { if ($('#mod-contact').val().length < 5) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } } // if (isEmpty($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Email address is required'); // return; // } // if (!isEmail($('#mod-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid email address'); // return; // } if (!isEmpty($('#mod-email').val())) { if (!isEmail($('#mod-email').val())) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid email address'); return; } } if($('#mod-email').val() =='') { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', 'Email address required'); return; } // if (!isEmpty($('#mod-other-email').val())) { // if (!isEmail($('#mod-other-email').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-other-email').focus(); // sweetAlertSimple('error', 'Oops...', 'Invalid other email address'); // return; // } // } var validate_data_contact_person = checkIfContactPersonIncomplete(); if (!validate_data_contact_person[0] && $('#contact-person-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the data of contact person first') return; } else if (!validate_data_contact_person[1]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid email') return; } else if (!validate_data_contact_person[2]) { addCustomerModalTabSelectedTab(2); $('#contact-person-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Contact person invalid mobile') return; } // if (isEmpty($('#mod-address-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-address-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary address is required'); // return; // } // if (isEmpty($('#mod-dd-city-1').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-1').focus(); // sweetAlertSimple('error', 'Oops...', 'Primary city is required'); // return; // } // if (!isEmpty($('#mod-address-2').val()) && isEmpty($('#mod-dd-city-2').val())) { // addCustomerModalTabSelectedTab(2); // $('#mod-dd-city-2').focus(); // sweetAlertSimple('error', 'Oops...', 'Select secondary city'); // return; // } if (!isEmpty($('#mod-dd-city-2').val())) { if (isEmpty($('#mod-address-2').val())) { addCustomerModalTabSelectedTab(2); $('#mod-address-2').focus(); sweetAlertSimple('error', 'Oops...', 'Enter secondary address'); return; } } var validate_data_children_list = checkIfChildrenIncomplete(); if (!validate_data_children_list[0] && $('#children-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the child details first'); return; } else if (!validate_data_children_list[1]) { addCustomerModalTabSelectedTab(3); $('#children-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', 'Children data invalid mobile'); return; } if (!checkIfInterestIncomplete() && $('#interest-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(5); $('#interest-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the interest/hobbies details first'); return; } if (!checkIfAffiliationsIncomplete() && $('#affiliations-list-table tbody tr').length > 0) { addCustomerModalTabSelectedTab(4); $('#affiliations-list-table select').first().focus(); sweetAlertSimple('error', 'Oops...', 'Complete the affiliations details first'); return; } // /check exist the input if($('#mod-other-mobile-number1').length > 0 && $('#mod-other-mobile-number1').val() != '') { $(this).attr("required", "true"); if ($('#mod-other-mobile-number1').val().length < 10 || !$('#mod-other-mobile-number1').val().startsWith("9")) { addCustomerModalTabSelectedTab(2); alert('error other mobile contact');return; $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } }else if($('#mod-other-mobile-number1').length ===1 && $('#mod-other-mobile-number1').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number1").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { } if($('#mod-other-mobile-number2').length > 0 && $('#mod-other-mobile-number2').val() != '') { // console.log('accept validation');return; if($('#mod-other-mobile-number2').val().length < 10 || !$('#mod-other-mobile-number2').val().startsWith("9")) { addCustomerModalTabSelectedTab(2);alert('error other mobile contact'); $('#mod-other-mobile-number2').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } if($('#mod-other-mobile-number1').val() == $('#mod-other-mobile-number2').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number2').val() == $('#mod-contact').val()) { sweetAlertSimple('error', 'Oops...', 'Duplicate mobile number'); return; } if($('#mod-other-mobile-number1').val().length > 10) { // $('#mod-other-mobile-number1').val(''); $('#mod-other-mobile-number1').focus(); sweetAlertSimple('error', 'Oops...', 'Invalid mobile number'); return; } } else if($('#mod-other-mobile-number2').length ===1 && $('#mod-other-mobile-number2').val()===''){ // console.log('accept validation');return; $("#mod-other-mobile-number2").prop('required',true); sweetAlertSimple('error', 'Oops...', 'Field required.'); $('#mod-other-mobile-number2').focus(); return; } else { console.log('dito'+$('#mod-other-mobile-number2').length); $('#mod-other-mobile-number2').attr("required", "false"); $('#mod-other-mobile-number2').removeAttr('required'); } // alert(force_update+ ' - '+force_update_reason); // console.log(getAllContactPersonTableData());return; $.ajax({ url: "api/customer/customerv2_update.php", method: "POST", dataType: 'json', data: { apiKey: '7347482808054211', customer_data: getCustomerAllModalData(), customer_dms: getAllDataSourceTableData(), customer_contact_person: getAllContactPersonTableData(), customer_children: getAllChildrenTableData(), customer_interest: getAllInterestTableData(), customer_affiliations: getAllAffiliationsTableData(), force_update : force_update, force_update_reason:force_update_reason }, beforeSend: function() { //show loader $('#proceed-button').attr('disabled', true); $('.customer-modal-overlay').show(); }, success: function(result) { if (parseInt(result.status) === 1) { sweetAlertSimple('success', 'Nice...', result.message); refreshTableCustomer(); $('#modal-customer').modal('hide'); } else if (parseInt(result.status) === 0) { sweetAlertSimple('error', 'Oops...', result.message); } else if (parseInt(result.status) === 2) { addCustomerModalTabSelectedTab(2); $('#mod-contact').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 3) { addCustomerModalTabSelectedTab(2); $('#mod-email').focus(); sweetAlertSimple('error', 'Oops...', result.message); if(customer_force_edit){ Swal.fire({ title: 'Update anyway?', input: 'textarea', inputPlaceholder: 'Enter your reason', confirmButtonText: `Save`, showCancelButton: true, inputValidator: (value) => { if (!value) { return 'Enter your reason to proceed.' }else{ force_update = 1; force_update_reason = value; $('#proceed-button').click(); } } }); } } else if (parseInt(result.status) === 4) { addCustomerModalTabSelectedTab(1); $('#data-source-list-table input').first().focus(); sweetAlertSimple('error', 'Oops...', result.message); } refreshModalReligion(); // refreshModalCities(); $('#proceed-button').attr('disabled', false); $('.customer-modal-overlay').hide(); force_update = 0; force_update_reason = ''; }, error: handleError }); }); $('#aha-status').on('change',function(){ if($(this).is(':checked')){ $(this).val('1'); }else{ $(this).val('0'); } }); $("#btn-add-mobile").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputMobLengh = $('.mod-div input[name="mob[]"]').length; // alert(inputMobLengh); if(inputMobLengh<2){ let divGrid = $('<div></div>').attr({'class':'mod-div'}); let inputGroup = $('<div></div>').attr({'class':'input-group mb-0 input-other-mob'}); let inputBtl = $('<div></div>').attr({'class' : 'edit-customer input-group-append'}).css("height", "28px");; let inputText = $('<div></div>').attr({'class':'input-group-text'}).text("+63"); let inputjson = $('<input>').attr({'name':'mob[]','id':'mod-other-mobile-number','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile', 'id':'mod-other-mobile-number2','type':'number','maxlength':'10','json-modal':'true'}); let label = $('<label></label>').attr({'for': 'Other Mobile','class':'lbl-forms mx-0 my-0'}).text("Other Mobile"); $(inputBtl).append(inputText); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger'}).click(function(e){ // count--; // $("#countInputMobile").prop("value",count); $(this).closest('.mod-div').remove(); inputMobLengh = inputMobLengh-1; if(inputMobLengh<2){ $("#btn-add-mobile").show(); } else { $("#btn-add-mobile").hide(); } $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); }); //end delete $(inputGroup).append(inputBtl,inputjson,deleteSPan); $(divGrid).append(label,inputGroup); $("#mod-contact-div").append(divGrid); // $("#countInputMobile").val(count); $('#mod-contact-div input[name="mob[]"]').each(function(index){ $(this).attr('id',"mod-other-mobile-number"+(index+1)); }); // alert(inputMobLengh); if(inputMobLengh>=1){ $("#btn-add-mobile").hide(); } else{ $("#btn-add-mobile").show(); } } //end if }); $("#btn-add-email").on('click', function(){ // var count = $("#countInputMobile").val(); // count++; let inputEmailCount =$('#email-add input[name="mob-email[]"]').length; if(inputEmailCount<2){ let divGrid = $('<div></div>').attr({'class':'col-sm-12 mb-1 div-email'}); let inputGroup = $('<div></div>').attr({'class':'form-group mb-0'}); let inputGroup2 = $('<div></div>').attr({'class':'input-group'}); let label = $('<label></label>').attr({'class':'lbl-forms mx-0 my-0'}).text("Other Email"); let inputjson = $('<input>').attr({'name':'mob-email[]','id':'mod-other-email','class':'big-letter edit-customer lbl-forms-sm form-control form-control-sm inputMobile','type':'email','json-modal':'true'}); let deleteSPan = $('<a><i class="fas fa-minus-circle"></i></a>').attr({'class':'customDeleleBtn float-right text-danger','required':true}).click(function(e){ inputEmailCount = inputEmailCount-1; // $("#countInputMobile").prop("value",count); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } // alert('fire') $(this).closest('.div-email').remove(); $('#email-add input[name="mob-email[]"]').each(function(index){ // $(this).attr('id',"mod-other-mobile-number"+(index+1)); $(this).attr('id',"mod-other-email"+(index+1)); }); }); //end delete $(inputGroup2).append(inputjson,deleteSPan); $(inputGroup).append(label,inputGroup2); $(divGrid).append(inputGroup); $('#email-add').append(divGrid); if(inputEmailCount>=1){ $("#btn-add-email").hide(); } else{ $("#btn-add-email").show(); } $('#email-add input[name="mob-email[]"]').each(function(index){ $(this).attr('id',"mod-other-email"+(index+1)); }); } //end if }); }); $(document).on('mousedown', ".is_active", function() { // Store the current value as the old value $(this).data("prev", $(this).val()); // console.log($(this).data("prev", $(this).val())) }); $(document).on('change', ".is_active", function() { let oldValue = $(this).data("prev"); if ($(this).val() =='0') { Swal.fire({ icon: 'warning', title: 'Oops!', text: "Status field is required.", allowEnterKey: true // default value }); $(this).val(oldValue); return false; // Prevent further execution if validation fails } Swal.fire({ title: 'Are you sure?', text: "You are about to execute this command. Do you want to proceed?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#d33', confirmButtonText: 'Yes, execute it!' }).then((result) => { if (result.isConfirmed) { let st = $(this).val();//($(this).is(':checked') ? 1 : 0); $.ajax({ url: "api/customer_update/dealer_view_assigned_cu.php", type: "POST", dataType: 'json', data: { apiKey: setpy,val: $(this).attr("data-id"),attr:st },success: function(result) { if(result.status==1) { Swal.fire({ icon: 'success', title: 'Success!', text: result.msg, allowEnterKey: true // default value }); // location.reload(); setTimeout(()=>{ Swal.close() ; location.reload(); },2000); }else{ Swal.fire({ icon: 'warning', title: 'Oops!', text: result.msg, allowEnterKey: true // default value }); } } }); } else { $(this).val(oldValue); } }); }); const goBack = () => { window.history.back(); } PK 8F�Z8��! �! activity_modal.jsnu �[��� PK 8F�Z {�� � 9"